Solved

Memory Leak question

Posted on 2002-06-05
18
296 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
  • 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

777 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