Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
INTRODUCTION AND RELEVANT INFORMATION:

The original project I work on has small memory leaks, so I have decided to perform a small test so I can detect what could cause them.

I have created a Win32 project using Visual Studio wizard. I haven't added anything, I have just left it as it was created with the wizard. I have used the tool GDIView ( http://www.nirsoft.net/utils/gdi_handles.html[^] ) to see if there are any inherent GDI leaks.

PROBLEM:

Each time I resize the window, this tool shows that there are +3 regions that my application leaks.

MY EFFORTS TO SOLVE THE PROBLEM:

Since the project was made by the Visual Studio wizard, I have tried to create a simple project from scratch, but the same +3 regions appear.

Reading through some articles on CodeProject about regions I have stumbled upon some demo applications that demonstrate the usage of them.

When I turn on GDIView these applications also leak +3 regions.

All of this is verified when I turn on Task Manager to see if the small memory leak is really occurring-it does occur since the memory slightly rises and stays constant afterwards no matter how many times I resize the window.

I use Microsoft Visual Studio 2008 Express Edition, but the problem was detected when empty project is created in regular Visual Studio 2008 as well.

I work on Windows XP, but the same effect happens on Windows 7.

QUESTION:

Why is this happening and how to eliminate these small memory leaks?

Thank you.

Best regards.
Posted
Updated 18-Dec-13 8:32am
v2
Comments
Richard MacCutchan 18-Dec-13 12:46pm    
Given thay you have not shown us any of the code, or pointed out where the leaks occur, it's impossible to suggest anything.
AlwaysLearningNewStuff 18-Dec-13 12:53pm    
That is exactly the problem!

I have just made the simplest Win32 projest with Visual Studio wizard. Nothing was added, and yet GDIView shows leak of 3 regions. So strange...

Thank you for the comment.

Best regards.
CPallini 18-Dec-13 12:55pm    
How do you check such memory leaks? I made a test with default Visual Studio 2012 generated Win32 App and nothing changes in GDIView, on application window resize.
AlwaysLearningNewStuff 18-Dec-13 13:20pm    
Here is how I do it:

First run GDIView;
Run demo application;
Resize it a bit;
Look at the columns in the GDIView;

Under regions column, and in the column All GDI will stand +3.

Regards.
CPallini 18-Dec-13 14:19pm    
OK, I am glad to learn new staff. Following your instructions I see no changes in All GDI (it is 17). My system: Visual Studio 2012 running on Windows 8.

1 solution

I do not wish to steal other people's credits so I post here a link to the answer that I think explains really well what is the problem:

http://stackoverflow.com/questions/20664677/default-win32-project-has-constant-number-of-memory-leaks[^]
 
Share this answer
 
Comments
CPallini 18-Dec-13 16:09pm    
It looks a great answer, however Win32 little-leaks make me worry a bit.
AlwaysLearningNewStuff 18-Dec-13 16:16pm    
Can you do our little test with the Windows 7, instead of Windows 8?

If there is +3 in All GDI, than we can safely assume they have fixed the problem.

Thank you.

EDIT:

I saw your comment above too late :)
Regards.
CPallini 19-Dec-13 2:11am    
Today WinXP. Possibly tomorrow Win7.
CPallini 19-Dec-13 3:28am    
On WinXp (32 bit, I forgot to mention my Win8 was 64 bit), Visual Studio 2005 generated project I found 33 [+4], that is I got +4 on the very first resize, than no more.
On the same WinXp, a Visual C++ 2010 Express genrated project I found the same result: 33 [+4] with +4 on first resize.
(both tests with debug build launched from within Visual Studio).
AlwaysLearningNewStuff 19-Dec-13 9:19am    
Thank you for your help, Mr.Pallini.

I think that this confirms that there are small memory leaks within Win32 projects ( both wizard generated ones and the ones made from "scratch" ).

I just hope that this is caused by the reasons provided in the link in my answer.

I still agree with you, that this is a little bit scary.

Best regards.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900