http://qs321.pair.com?node_id=1209159


in reply to Strange memory growth

In lvalue context,

$var->{$key}
is equivalent to
( $var //= {} )->{$key}
so
defined( $cg->{mainsnak}{datavalue}{value}{notexist} )

is equivalent to

defined( ( ( ( ( $cg //= {} )->{mainsnak} //= {} )->{datavalue} //= {} + )->{value} //= {} )->{notexist} )

That could potentially create a lot of new hashes.

Solution 1:

if ( $cg && $cg->{mainsnak} && $cg->{mainsnak}{datavalue} && $cg->{mainsnak}{datavalue}{value} && defined( $cg->{mainsnak}{datavalue}{value}{notexist} ) ) { ... }

Solution 2:

no autovivification; if (defined( $cg->{mainsnak}{datavalue}{value}{notexist} )) { ... }

Replies are listed 'Best First'.
Re^2: Strange memory growth
by tinita (Parson) on Feb 14, 2018 at 18:50 UTC
    That could potentially create a lot of new hashes.
    But only three, and $cg (and $jp) fall out of scope after every iteration. I can't see why this would continually increase memory.

      Indeed. As such, I find it hard to believe the line you identified has anything to do with a memory leak. Is that the program you actually ran?

        I find it hard to believe the line you identified has anything to do with it, then.
        I'm not the author of the question.