Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Not able to release memory

by demerphq (Chancellor)
on Mar 03, 2004 at 08:19 UTC ( #333477=note: print w/ replies, xml ) Need Help??

in reply to Not able to release memory

Ok, there are a few things.

First as others have commented the OS manages allocating and freeing memory, and typically doesnt bother. But with modern OS'es swapping etc, im not sure why it should be a problem, maybe on *nix its different to win32.

Second you are creating 1000 * 100 * 100 keys, which means 10,000,000 keys, which also means a hash stucture of 16,777,216 value slots as internally there will always be next power of 2 value slots vs keys. The best way to reduce the memory footprint of something like this is to use a DB or a hash tied to a DB of some form, possibly cached by a real hash for speed on frequent fetches. A tied DB_File B+Tree is often a reasonable option.

Third your style is ah, very C like. :-)

#!/usr/bin/perl -w use strict; my %hash; for my $i (1..1000) { for my $j (1..100) { for my $k (1..100) { $hash{$i,$j,$k} = 1 } } } print "Check Memory usage NOW and press enter\n"; my $chk=<>; %hash=(); print "Check Memory usage NOW and press enter\n"; $chk=<>;



    First they ignore you, then they laugh at you, then they fight you, then you win.
    -- Gandhi

Comment on Re: Not able to release memory
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2015-11-29 12:15 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (750 votes), past polls