Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re:^2 Storable: where is my memory?

by ph0enix (Friar)
on Dec 13, 2002 at 07:53 UTC ( #219527=note: print w/replies, xml ) Need Help??

in reply to Re: Storable: where is my memory?
in thread Storable: where is my memory?

Well. This piece of code should simulate what goes on when tied hash is used. I have tied hash to PostgreSQL database so key-value pairs are stored in database and does not reside in memory. Because stored values are deeper structures (in most simpliest case the stored value is list of Set::Scalar objects) there is the Storable module used for converting to the scalar.

There is nfreeze called when storing value to the database and thaw when data retrieval from it. I expect that all temporary variables are freed when goes out of scope, but it looks like not. procinfo function is called when all variables ($tmp, $r_arr, $set and $scalar_set) are out of their scope and so I expect that displayed values should be the same...

My big problem is memory compsumption when I iterate through all keys in this tied hash. For relatively small piece of test data the first iteration cost about 750 MB and each other cycle causes perl to require about 200 MB more! So after third cycle is allocated more than 1GB!!!

Simple empty loop with this tied hash which causes memory compsumption...

while (my ($key, $value) = each %data) { ; }

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://219527]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2023-12-02 18:28 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (18 votes). Check out past polls.