Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Strange memory growth

by ikegami (Patriarch)
on Feb 14, 2018 at 18:26 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1209159]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-28 15:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found