|
-
November 16th, 2005, 12:11 PM
#3
Re: Memory Freeing Problem
 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.
 Originally Posted by raed_hasan
::CreateStreamOnHGlobal(NULL,TRUE,&pStream);
Check return values for success.
 Originally Posted by raed_hasan
the memory is keep increase after each call and nothing is freed,
Where did you see this memory "increase"?
 Originally Posted by raed_hasan
pStream->Release();
If you use the smart pointer, you comment this line out.
 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:
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|