CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Threaded View

  1. #3
    Join Date
    Oct 2002
    Location
    Germany
    Posts
    6,205

    Re: Memory Freeing Problem

    Quote Originally Posted by raed_hasan
    IStream *pStream;
    Please don't use raw interface pointers.

    This is better written as -
    Code:
    CComQIPtr <IStream> pStream;
    ...You will not have to worry about reference counting - the smart pointer will release for you when it goes out of scope.

    Quote Originally Posted by raed_hasan
    ::CreateStreamOnHGlobal(NULL,TRUE,&pStream);
    Check return values for success.
    Quote Originally Posted by raed_hasan
    the memory is keep increase after each call and nothing is freed,
    Where did you see this memory "increase"?
    Quote Originally Posted by raed_hasan
    pStream->Release();
    If you use the smart pointer, you comment this line out.

    Quote Originally Posted by raed_hasan
    I also tried to use GlobalFree(pStream), and GlobalFree(&pStream) with no avail. memory keep rasing after each call
    Naturally to no avail. GlobalFree accepts a HGLOBAL and not an interface pointer. You are lucky worse things didn't happen.

    Anyways, you don't need to do this.

    Reason:
    Quote Originally Posted by MSDN
    CreateStreamOnHGlobal -

    If the caller sets the fDeleteOnRelease parameter to FALSE, then the caller must also free the hGlobal after the final release. If the caller sets the fDeleteOnRelease parameter to TRUE, the final release will automatically free the hGlobal as shown in the following code excerpt.
    Last edited by Siddhartha; November 16th, 2005 at 12:14 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured