Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I'm trying to understand whether a large program I'm dealing with has memory leaks. I did some search, and in all the places where Perl's memory use is discussed, it says something like this:
- Perl's garbage collector works by counting references.
- If your code contains circular references, the garbage collector will not be able to free that memory, as the reference count won't go down to 0.
- The simple solution is to use weakened refs.
- If you don't do this, the memory will not be freed until the program is terminated.
Now, the code I'm dealing with certainly contains circular references. But before I start looking up all those and weakening them, I wanted to understand something:
If I reach the end of my program, and it terminates as it should - is the memory with the circular references freed anyway? If it is, does it mean that technically, there can be no such thing as a memory leak in perl as long as the program isn't interrupted? What happens if it is interrupted? I couldn't find definite answers to these questions...
Thanks a lot!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Memory and garbage collection
by moritz (Cardinal) on Jul 30, 2008 at 12:50 UTC | |
by Anonymous Monk on Jul 30, 2008 at 13:24 UTC | |
by moritz (Cardinal) on Jul 30, 2008 at 13:30 UTC | |
by jethro (Monsignor) on Jul 30, 2008 at 13:45 UTC | |
|
Re: Memory and garbage collection
by dragonchild (Archbishop) on Jul 30, 2008 at 13:25 UTC | |
|
Re: Memory and garbage collection
by pjotrik (Friar) on Jul 30, 2008 at 13:10 UTC | |
|
Re: Memory and garbage collection
by Limbic~Region (Chancellor) on Jul 30, 2008 at 13:33 UTC | |
|
Re: Memory and garbage collection
by Khen1950fx (Canon) on Jul 30, 2008 at 13:21 UTC | |
by Anonymous Monk on Jul 30, 2008 at 13:26 UTC |