Hi monks

In one of my app I'm using hash of objects. Each object hold it's own data as key - value pairs which are tied to the PostgreSQL database via Tie::RDBM module. Tieing to database is used to minimize physical memory requirements.

My problem is memory greediness. When I iterate through all key - value pairs there is allocated new additional memory which is not released... :( Function which iterate through key - value pairs is method of this object.

package Elric::Lexicon; sub new { # so a lexicon is basically a hash (of entries) return bless {}, shift; } sub info { my $self = shift; my $num_keys = 0; my $num_mu = 0; my $key; my $value; &message("Buckets used/allocated:\t".scalar(%{$self})."\n"); while(($key,$value) = each %$self) { $num_keys++; $num_mu += scalar(@$value); } return $num_mu; } sub bind { my $self = shift; my $type = shift; my $lang = shift; if ($type eq 'rdbm') { my $esd = \%Elric::System::default; # test if connectdb called before if (!defined $$esd{db}->{pass}) { message("error: can't bind... use connectdb first\n"); return 0; } eval "use Tie::RDBM;" if ! defined $INC{'Tie::RDBM.pm'}; tie (%$self, 'Tie::RDBM', { db => "dbi:$$esd{db}->{type}:". "dbname=$$esd{db}->{name};". "host=$$esd{db}->{host};". "port=$$esd{db}->{port};", user => $$esd{db}->{user}, password => $$esd{db}->{pass}, table => $lang, create => 1, drop => 1, autocommit => 1, DEBUG => 0 }) or die $!; } return 1; } ...

This code is called from the main program

use Elric::Lexicon; my %lexicon = (); ... $lexicon{'EN'} = Elric::Lexicon->new; $lexicon{'EN'}->bind('rdbm', 'EN'); ... my $mind_units = 0; foreach (sort keys %lexicon) { # iterate all present lexica &message("Lexicon $_:\t"); # name the current lexicon $mind_units += $lexicon{$_}->info(); # print information about it +s internals }

Any suggestions welcome


In reply to iteration through tied hash eat my memory by ph0enix

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.