Oops I goofed with the $self->{self}= $self; I was just experimenting around with storing the object's name in it's own namespace, and stupidly left that in there. Circular reference is now imprinted in my memory.

But even if I remove it, and not call DESTROY myself, and take all references to the objects out of scope, the memory is not reused. So can anyone show how to prevent the memory doubling in the following? I use 2 different hashes, and undef the first, so why isn't the memory available for the second hash to reuse? I would guess that it is somehow not releasing the array's used in $self->{stuff}, but if I put @{$self->{stuff}} = () in the DESTROY sub, it dosn't clear it.

#!/usr/bin/perl use warnings; use strict; my %bubs; my %bubs1; for(1.. 500){ $bubs{$_} = ZtkBubject->new( -name => $_, ); $bubs{$_}=(); delete $bubs{$_}; $bubs{$_}=(); } %bubs = (); undef %bubs; print "Check memory now and hit enter\n"; <>; for(1.. 500){ $bubs1{$_} = ZtkBubject->new( -name => $_, ); } print "Check memory now and hit enter, its doubled\n"; <>; #===================================================================== +======== # ZtkBubject Class #===================================================================== +======== package ZtkBubject; use strict 'vars'; use Carp; sub new { my ($class, %arg) = @_; my $self = { 'name' => $arg{-name}, }; bless $self; # print "just blessed $self\n"; $self->{stuff} = [1..1000]; #add some memory usage return $self; } ############################################# sub DESTROY{ my ($self) = @_; @{$self->{stuff}} = (); print "destroying->", $self->{name},' ',$self,"\n"; } ########################################### 1;

I'm not really a human, but I play one on earth. flash japh

In reply to Re: Is there a penalty for namespace use? by zentara
in thread Is there a penalty for namespace use? by zentara

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.