Archived

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

Windows Leeks

This topic is 6387 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

I am trying to write a windows text editor that has a more attractive look (it looks a bit like sonique). But I am getting a memory leeks every time I redisplaying or resizing the app. I have separate functions to paint and resize the main window that I call when the appropriate message is sent to the app. And here seems to lie the problem because if I call them out side the msg look I don''t get any memory leeks but it is very inefficient and untidy code. Here is the main gist of the message proc: switch (uMsg) { case WM_PAINT: DisplayWindow(); break; case WM_MOUSEMOVE: if (wParam == MK_LBUTTON) { SetWindowPos( hWnd,HWND_TOP,wdXPos,wdYPos,wdWidth,wdHeight,NULL); } else { CalcRGN(); // Calculate the windows new region SetWindowPos( hWnd,HWND_TOP,wdXPos,wdYPos,wdWidth,wdHeight,NULL); DisplayWindow(); } } Any help or a website that has got advanced windows programming tuts (ie stopping mem leeks) would be much appreciated I am not using MFC because I want to learn as much about windows programming as possible.

Share this post


Link to post
Share on other sites
Are you using VC++? If you are, then check out _CrtDumpMemoryLeaks() and related functions in the MSDN docs. There are a bunch of runtime library functions that will help you to detect memory leaks if you run your program from the debugger. You can find out if and where a leak is occuring, as well as see a dump of some of the data from the leak.

Good luck!

Share this post


Link to post
Share on other sites
If you''re not using VC++, you might be able to do what they do. They overloaded the new and delete operators with different parameters. Then they used a define to redifine them. It does take a lot of work though.

For a good time hit Alt-F4! Go ahead try it, all the cool people are doing it.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Your code does not show alot so I''m guessing here.

A common problem is that reources are not deleted once they are no longer needed, i.e. CreateBrush, CreateFont, etc....

Remember to deselect them from the DC first.

SelectObject(HDC hDC,HGDIOBJ hObj) returns the previously selected object type (i.e. if you select a pen then it returns the previous pen), us this returned value to deselect your object.

Share this post


Link to post
Share on other sites