• Advertisement

Archived

This topic is now archived and is closed to further replies.

memory leak problems

This topic is 5591 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

memory leak problems Whats types of code can give a memory leak ? Whats the best way to find a memory leaks if you have lots and lots of code and it's not even your code how do you find them? line by line? windows gdi+ has given me some problems can you see the leak? const int BMAP=80; const int BREC=BMAP*BMAP; long deltaX =BMAP*20; long deltaY =BMAP*20; static RECT rctGrid; // grid-window rectangle static RECT rect[BREC]; // grid-cell array HRGN hrgnCell; // test-region handle HDC hdc; // device context (DC) handle float x, y; // drawing coordinates POINTS ptlHit; // mouse coordinates int i; // count variable PAINTSTRUCT ps; hdc = GetDC(hdlg); Graphics* myGraphics; Pen* pen; pen = new Pen(Color(255-LC.A,LC.R,LC.G,LC.B), 1); myGraphics = new Graphics(hdc); SolidBrush solidBrush(Color()); //lots of stuff //releaseing and deleteing ReleaseDC(hdlg, hdc); delete myGraphics; delete pen; DeleteObject(hrgnCell); this code is called several times a secound. I lose a megabit every 3 seconds times. what's leaking? [edited by - markdezonia on November 1, 2002 7:08:53 AM]

Share this post


Link to post
Share on other sites
Advertisement
Lint/Splint your code. It will find gobs o'' possible erros, you''ll be surprised what it can find. 10 errors in a 6 line function is not that unusual.

www.splint.org
(And RTFM goes with this tool. It''s quite advanced) :-)

_____________________________________________________
GigaSunet http://basun.sunet.se/aktuellt/giga2.html
10Gbit/sec.....wooooooooooohoooooooooooo....

Share this post


Link to post
Share on other sites
Try deleting the Graphics object before releasing the DC. Deconstruction should occur in the opposite order as construction.

Share this post


Link to post
Share on other sites
its also generally a good rule of thumb not to dynamically allocate/deallocate memory on a per-frame basis. wouldn''t it be easier to define them before the frame loop, and delete them after?

Share this post


Link to post
Share on other sites

  • Advertisement