Hello all,
in the perl documentation I've read about some statements that could result in memory leaks, but I don't understand what the real problem is and if some code I use should be avoided because it has the same problem. I would be happy if someone could give me some advise and lighten my darkness.
Let me quote:
A more serious concern is that unreachable memory with a non-zero reference count will not normally get freed. Therefore, this is a bad idea:{ my $a; $a = \$a; }
http://perldoc.perl.org/perlobj.html#Two-Phased-Garbage-Collection
Is the problem that $a is declared in the block, but never assigned with something and never used elsewhere? If I would assign $a a value from somewhere and do use it somewhere else, do I have the same problem?
I have code like the following:
sub foo { my $retVal = undef; $retVal = $someObject->bar()->doSomething(); $retVal = \$retVal; Log4perl->debug('retval: ', sub {$retVal}); return $retVal; }
The goal of the above is to let foo return a reference to a string, but just have to create that reference once and to use it as a return value and for logging purposes. Does this produces memory leaks like stated in the perl documentation?
Thanks for your hints.
In reply to unreachable memory with a non-zero reference count by Pickwick
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |