Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Strange memory growth

by ikegami (Pope)
on Feb 14, 2018 at 18:26 UTC ( #1209159=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1209159]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2018-04-25 10:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?