|
-
February 23rd, 2009, 02:15 AM
#1
Memory leak or not memory leak?
Hi!
I currently looking for memory leak in my application. After I found out one operation that seems to make a memory leak from the task manager, I decided to test one thing (since I know I can't trust the task manager information).
I created 3 small windows applications by using the project wizard of visual studio 2008, using default settings.
In the first application, I do nothing else, just run it - pretty simple.
In the second application, I just add at the end of the "InitInstance" member function of my class application the following lines:
BYTE **up_info = new BYTE *[80000];
for (int i=0; i<80000; i++) up_info[i] = new BYTE[512];
for (int i=0; i<80000; i++) delete[] up_info[i];
delete[] up_info;
In the third application, I did the same thing than for the second application with adding a loop on this memory allocation/deallocation a big number of time.
I believe that my code does not have memory leak. Tell me if I am wrong.
After the memory allocation/desallocation has been finished for each of the 3 applications, I checked the memory information through the Process Explorer application.
Here are the information:
Type of memory / First Application / Second Application / Third Application
Working set / 15,584 K / 19,180 K / 50,324 K
WS Private / 3,428 K / 7,020 K / 38,152 K
WS Shareable / 12,156 K / 12,160 K / 12,172 K
WS Shared / 10,912 K / 10,896 K / 10,912 K
Private Bytes / 4,632 K / 8,160 K / 39,408 K
Virtual Size / 118,644 K / 165,364 K / 197,748 K
Peak Private Bytes / 8,688 K / 47,580 K / 49,412 K
Peak Working set / 19,572 K / 55,896 K / 57,396 K
In case of the third application, the memory is increasing until stabilizing to a certain value. I stopped the loop when the memory usage was stable in the Task manager.
So here are my questions:
Since I truely believe that my code doesn't generate memory leaks, why does the private bytes has increased so much in the case of the third application?
How can I read all theses memory values to determine whether I have a memory leak or not?
During the loop of the third application, the number of page fault is increasing a lot. Why?
Thanks for you time,
madric
-
February 23rd, 2009, 02:42 AM
#2
Re: Memory leak or not memory leak?
No, that code doesn't have memory leaks. If you want memory leak reports, use a specialized tool, not task manager or PE.
-
February 23rd, 2009, 03:06 AM
#3
Re: Memory leak or not memory leak?
So why the private bytes is over 38MB for the third application?
And what specialized tool should I use?
-
February 23rd, 2009, 03:52 AM
#4
Re: Memory leak or not memory leak?
"Devise the simplest possible solution that solves the problems"
-
February 23rd, 2009, 06:08 AM
#5
Re: Memory leak or not memory leak?
 Originally Posted by madric
So why the private bytes is over 38MB for the third application?
And what specialized tool should I use?
There are commercial tools and also free tools. I've used this Visual Leak Detector several times.
http://dmoulding.googlepages.com/vld
http://www.codeproject.com/KB/applic...kdetector.aspx
-
February 23rd, 2009, 07:22 AM
#6
Re: Memory leak or not memory leak?
ok thanks, I will look into those softwares.
But, just wonder...
There is no way to know how much memory my application has really allocated from all the statistics given from Process Explorer?
-
February 23rd, 2009, 08:35 AM
#7
Re: Memory leak or not memory leak?
You should think of the virtual memory footprint in PE as sort of an approximate "peak memory used at once" measure for the program. There's not a whole lot of reason for that to get smaller when actual usage decreases (although it sometimes may). Plus there are behind-the-scenes OS factors which may jiggle the numbers around a bit. So no, in exact terms, you can't rely on PE for much of anything except detecting whether you're leaking memory like a sieve.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|