Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Memory Leak question

Posted on 2002-06-05
18
Medium Priority
?
304 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 800 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

Technology Partners: 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

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
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 column That will then direct you to their download page. From that p…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

971 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