Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

Memory Leak question

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
Hill8982
Asked:
Hill8982
  • 7
  • 6
  • 4
  • +1
1 Solution
 
jkrCommented:
>>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
 
Hill8982Author Commented:
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
 
jkrCommented:
Well, that page table thing was addressing the UN*X part :o)
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Hill8982Author Commented:
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
 
jkrCommented:
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
 
Hill8982Author Commented:
>>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
 
Hill8982Author Commented:
Exactly how could I verify that there is no leak after running above program?
0
 
jkrCommented:
'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
 
Hill8982Author Commented:
>>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
 
jkrCommented:
Well, then what about 'top'? :o)
0
 
nietodCommented:
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
 
Hill8982Author Commented:
>>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
 
Hill8982Author Commented:
>>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
 
AxterCommented:
0
 
AxterCommented:
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
 
AxterCommented:
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
 
AxterCommented:
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
 
jkrCommented:
>>Example code to call jkr's memory leak program

Axter, please do not call that a "program" :o)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 7
  • 6
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now