| | |
Advanced Question
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jun 2005
Posts: 6
Reputation:
Solved Threads: 0
Hi
Does anyone know why the following code causes me a memory leak:
<< moderator edit: added [code][/code] tags >>
NOTE: the imageptr is a pointer to my jpeg image, and aJpegSize is the size of the image. I later go on to do:
I'm really stuck, any idea could help!
Thanks in advance,
maldini
Does anyone know why the following code causes me a memory leak:
C Syntax (Toggle Plain Text)
HGLOBAL hGlobal = GlobalAlloc( GMEM_FIXED, aJpegSize ); void* p = GlobalLock(hGlobal); memcpy((char *)p,imageptr,aJpegSize); GlobalUnlock(hGlobal); IStream* pStream = NULL; if ( CreateStreamOnHGlobal( hGlobal, TRUE, &pStream ) == S_OK); { if ( aPicture == NULL ) delete aPicture; aPicture = Image::FromStream(pStream,0); } pStream->Release(); GlobalFree(hGlobal);
NOTE: the imageptr is a pointer to my jpeg image, and aJpegSize is the size of the image. I later go on to do:
C Syntax (Toggle Plain Text)
Graphics graphics( dc ); graphics.DrawImage( w->aPicture, 0, 0, 320, 240 );
I'm really stuck, any idea could help!
Thanks in advance,
maldini
•
•
Join Date: Jun 2005
Posts: 6
Reputation:
Solved Threads: 0
Found my own answer:::::::
For those interested,,,,, the pointer aPicture ( which is of type Image ) must be delete at some point, or else it never call the destructor, which in tern never deallocates its memory.
Therefore I now have this somewhere in my code:
if ( w->aPicture != NULL )
{
delete w->aPicture; // Relese the memory allocated by aPicture
w->aPicture = 0;
}
Cheers
maldini
"What does'nt kill you, makes you stronger"
For those interested,,,,, the pointer aPicture ( which is of type Image ) must be delete at some point, or else it never call the destructor, which in tern never deallocates its memory.
Therefore I now have this somewhere in my code:
if ( w->aPicture != NULL )
{
delete w->aPicture; // Relese the memory allocated by aPicture
w->aPicture = 0;
}
Cheers
maldini
"What does'nt kill you, makes you stronger"
![]() |
Similar Threads
- learning php (PHP)
- I got a question... (IT Professionals' Lounge)
- Expires header? (PHP)
- ULTIMATE HARD DISK SETTINGS - brain racking question (Storage)
- Finding API in DLL (C++)
- Changing Network Configuration (*nix Software)
Other Threads in the C Forum
- Previous Thread: Help, with transforming some numbers
- Next Thread: Initialization of Const Arrays by function
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays asterisks binarysearch calculate centimeter char convert copyanyfile copyimagefile copypdffile cprogramme createcopyoffile csyntax directory drawing dynamic executable fflush file fork frequency getlasterror givemetehcodez graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators infiniteloop initialization interest km lazy linked linkedlist linux linuxsegmentationfault list locate logical_drives match matrix microsoft motherboard multi mysql number open opendocumentformat opensource owf pattern pdf performance pointer pointers posix power problem probleminc program programming pyramidusingturboccodes read recursion recv repetition scanf scheduling scripting segmentationfault send shape socketprograming spoonfeeding stack standard string strings structures student suggestions systemcall test testautomation unix user variable voidmain() wab win32api windows.h





