How can memory leaks be found experimentally?

I want to test a function for memory leaks.

Can I just compile a program that loops it an arbitrarily large number of times and see if the computer eventually crashes? Or is there a better way to see if the memory is getting eatten?
When I can't use a memory debugger, I do either of these:
* Run the function several times while checking the program's memory usage in a system monitor. If I see that the memory usage grows with each call when that shouldn't happen, I know there's a memory leak.
* If the allocations are big enough and slow enough, I can use the system monitor without looping anything (I may not even be able to it without radically modifying the program, anyway). For example, suppose I know that when the user clicks a button, some large resource will be loaded, and when they click a different button, it will be unloaded. If the system monitor reports that memory usage is only growing, never shrinking, I know that the memory for the resource is not getting freed.
However, if I have access to a memory debugger, I'll just use that, since it's much more reliable than any of these methods.
If I compile a program with memory leaks, will they be cleaned up when it's closed? Or do I need to keep it running to observe the leaks?
On modern OSs with virtual memory, yes, leaks are plugged when the program terminates.
Topic archived. No new replies allowed.