Solved

Memory Leak question

Posted on 2002-06-05
18
298 Views
Last Modified: 2013-12-14
If you have an executable, and it has a memory leak, does the memory leak go away when the executable quits?

In other words when you close the application, or when the application exits, is all the memory free'd that was created with new()?

If this issue is platform depedent, my targets is Unix, but I still would be interested in Win32 target information not related to API functions leaks.

Thanks in advance
0
Comment
Question by:Hill8982
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 4
  • +1
18 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 7056482
>>If you have an executable, and it has a memory leak,
>>does the memory leak go away when the executable
>>quits?

It is hard to give a general answer, but, for most 'modern' OSs, it should be 'yes' and deefinitely is 'yes' for Win32 (not to talk of resource leaks on Win9x). Memory used by an application is listed in 'page table directories', and once a process exits, the alloted memory is freed again.
0
 

Author Comment

by:Hill8982
ID: 7056689
jkr,
Thanks for the Win32 information.

I'm looking for a difinitive answer with the Unix platform.  Specifically DEC, Sun, and HP.
If someone can give a good refference, I'll increase the points.

The reason I'm looking for this information, is that I've been asked to research memory-leak tools in order to test my Unix application.
But I don't think it's necessary because my application is a command line application that runs and exits in a matter of seconds.

My Boss tells me that memory leaks do persist after the executable exits.  So I'm looking for documentation that will either show he's right or wrong.
0
 
LVL 86

Expert Comment

by:jkr
ID: 7056767
Well, that page table thing was addressing the UN*X part :o)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Hill8982
ID: 7056790
jkr,
>>Well, that page table thing was addressing the UN*X part :o)
Ohh!  I didn't get that.

Not that I'm doubting your word, but I'm looking for something I can show to my Boss, (Other then a link to this question) :-)

Do you know of any links or books that would verify this information?
0
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 7056845
What about a demonstration? Just use this 'program'

void main () {

char *p = new char [ 100000000];

}

and take a look at e.g. /proc/meminfo before and after
0
 

Author Comment

by:Hill8982
ID: 7056872
>>and take a look at e.g. /proc/meminfo before and after

I don't understand.  Is there a meminfo program?  

I know there's a meminfo struct and a meminfo function, but I'm not sure how to get current available memory from that, and wouldn't other running processes currupt the data?
0
 

Author Comment

by:Hill8982
ID: 7056879
Exactly how could I verify that there is no leak after running above program?
0
 
LVL 86

Expert Comment

by:jkr
ID: 7056893
'meminfo' is a 'file' in the /proc filesystem, where a lot of kernel facilities are exposed in a filesystem-like fashion - this is also a 'common feature' of the newer UN*X-OSs.
0
 

Author Comment

by:Hill8982
ID: 7056938
>>this is also a 'common feature' of the newer UN*X-OSs.

Doesn't seem to be available in any of the Servers I have access to.
0
 
LVL 86

Expert Comment

by:jkr
ID: 7056947
Well, then what about 'top'? :o)
0
 
LVL 22

Expert Comment

by:nietod
ID: 7057094
Of course its a good idea to avoid memory leaks in the first place.  You might consider using classes to automate memory lifetime, like smart pointer classes.   In 8+ years I have not had even 1 memory leak reported in my application (except for intentional ones) because I automate all dynamic memory alocations.
0
 

Author Comment

by:Hill8982
ID: 7057326
>>Of course its a good idea to avoid memory leaks in the
>>first place.  
Of course.
I'm inherting which my boss does not want to change unless neccessary.
In my own code, I don't create memory with dumb pointers directly.
0
 

Author Comment

by:Hill8982
ID: 7057332
>>Well, then what about 'top'? :o)
This gives a lot of information.  How can I tell what is being effected by a possible memory leak?
0
 
LVL 30

Expert Comment

by:Axter
ID: 7057445
0
 
LVL 30

Expert Comment

by:Axter
ID: 7057451
Example code to call jkr's memory leak program.
Compiled on DEC, but should work for Sun and HP.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/resource.h>


int main ()
{
 rusage r1,r2;
 memset(&r2, 0, sizeof(r2));
 getrusage(RUSAGE_SELF, &r1);

 system("memleak"); //call jkr's memleak program

 getrusage(RUSAGE_SELF, &r2);

 printf("unshared data %i/%i\nunshared stack %i/%i\nshared memory size %i/%i\n",
        r1.ru_idrss, r2.ru_idrss, r1.ru_isrss, r2.ru_isrss, r1.ru_ixrss, r2.ru_ixrss);
 return 0;
}
0
 
LVL 30

Expert Comment

by:Axter
ID: 7057461
FYI:
If you want to use top and you want to narrow the focus to specific user, you can use the following method for DEC:
top -Udmaisona

On other platforms, the following method should work:
top -d15 | grep dmaisona

Where 15 is how many times it does a repeat before it quits.
0
 
LVL 30

Expert Comment

by:Axter
ID: 7057479
Here's another link you can check out:
http://saru.nendai.nagoya-u.ac.jp/global/sys/HTML/S/kern%20kern_exit.c.html

I'm not sure about Sun and HP, but DEC uses kern_exit.c.
According to above link, "Exit" deallocate address space and other resources.

Not very diffinitive....
0
 
LVL 86

Expert Comment

by:jkr
ID: 7058015
>>Example code to call jkr's memory leak program

Axter, please do not call that a "program" :o)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C++ Language error 28 316
c++ syntax question 9 67
How can I build my own IDE using ASP.NET MVC? 2 82
Android development question 2 110
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question