| | |
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 |
#include * append array arrays asterisks bash binarysearch calculate changingto char character cm copyimagefile creafecopyofanytypeoffileinc createprocess() database dynamic execv feet fgets file floatingpointvalidation fork forloop framework function getlogicaldrivestrin givemetehcodez global grade gtkwinlinux hacking histogram ide include incrementoperators input intmain() iso kernel keyboard kilometer km license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix meter microsoft mqqueue number oddnumber odf opensource openwebfoundation overwrite owf pdf performance pointer posix probleminc process program programming radix recursion recv recvblocked research reversing scripting segmentationfault sequential single socket socketprogramming standard strchr string systemcall testing threads turboc unix urboc user variable wab whythiscodecausesegmentationfault windowsapi





