in reply to Re: unreachable memory with a non-zero reference count
in thread unreachable memory with a non-zero reference count

Why you first assign $someObject->bar()->doSomething(); to it, then discard the result is not clear to me. Nor is it clear to me what Log4perl->debug should do with its second argument.
It just was an example, because I have methodes which work like that. doSomething() provides a string, but I need a reference to that string to send it to the calle of foo. I thought my line is more readable than $retVal = \$someObject->bar()->doSomething(); or user \$retVal wherever I want the reference. The second parameter to debug is only called when Log4perl actually logs something and used in the log message. The documentation of Log4perl prefers using anonymous subs with references to data when logging large strings because the strings won't be copied if the current log level is not debug.
  • Comment on Re^2: unreachable memory with a non-zero reference count

Replies are listed 'Best First'.
Re^3: unreachable memory with a non-zero reference count
by JavaFan (Canon) on Jun 22, 2010 at 03:36 UTC
    Your line may be more readable, it's not returning a reference to the string. It's returning a reference to itself.
    use 5.10.0; use strict; use warnings; sub foo {"A string"}; my $object = bless []; my $retVal1 = \$object->foo; my $retVal2 = $object->foo; $retVal2 = \$retVal2; say "$retVal1: $$retVal1"; say "$retVal2: $$retVal2"; say $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$retVal2; __END__ SCALAR(0x893c2c8): A string REF(0x894d1f4): REF(0x894d1f4) REF(0x8d9b1f4)