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} )) { ... }