Welcome to the Monastery | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
I'll just pretend the 3rd "my" in your code isn't there. Others have already pointed it out...
One may still perform a variety of operations on the hash reference (and consequently the hash itself). Is this correct? Yes, and that's why this isn't a memory leak :-) Java has the same behaviour in this case: if you can get at it, it's kept in memory.
To reduce the reference count to 'zero' (eliminating any potential memory leak that is present), I could simply set the $hash_ref variable to 'undef'(?)You could. You could also let the reference go out of scope, and it will be cleaned up automatically. The only problem with a reference counting garbage collector are circular references. Like this:
The reason %monks is not collected is because there still is a reference to %monks in $monks{myself}. $monks{myself} would be removed if %monks were collected, but there is still a reference to %monks in $monks{myself}... etc... A mark-and-sweep collector can detect these circular references and would also collect %monks here. Perl doesn't (except at the end of execution).
In reply to Re: Memory leaks and reference counting within Perl.
by Joost
|
|