in reply to Memory Leak with XBase?

In our experience OO perl, running persistently 'leaks' ie you observe a consistent growth in memory usage over time despite the fact that there is not more internal data being stored by the widget. Interesting observations include when you 'de OOify' things the leaks tend to become much smaller or dissapear entirely, and calling it a leak is not entirely correct because if you push the system into swap these 'leaky' processes suddenly shrink to a small fraction of there size - unload the system so there is no swap and they stay small but slowly grow over time.

Sometimes undef stuff helps. Rewriting it into a more functional style will probably work as well if it really matters. It will probably make no difference but in the close code you could make an undef change (XBase::Base::close())

sub close { my $self = shift; $self->NullError(); if (not defined $self->{'fh'}) { $self->Error("Can't close file that is not opened\n"); return 0; } $self->{'fh'}->close(); # remove what should be the last ref to the IO::File # object dropped into self on the open undef $self->{'fh'}; # original code called delete like this, may as well stay delete $self->{'fh'}; 1; }

cheers

tachyon

Replies are listed 'Best First'.
Re: Re: Memory Leak with XBase?
by Anonymous Monk on Mar 18, 2004 at 03:31 UTC
    In our experience OO perl, running persistently 'leaks' ie you observe a consistent growth in memory usage over time despite the fact that there is not more internal data being stored by the widget.
    All that says is that whatever OO perl you're using creates circular references, which is a programmer error.

      The example code presented calls all of 4 functions. new() and open in XBase::Base and IO::File's open and close methods. Please show me the circular reference in this code.

      cheers

      tachyon

Re: Re: Memory Leak with XBase?
by tigervamp (Friar) on Mar 18, 2004 at 02:45 UTC
    In our experience OO perl, running persistently 'leaks' ie you observe a consistent growth in memory usage over time despite the fact that there is not more internal data being stored by the widget.

    I have come to realize that of late.

    and calling it a leak is not entirely correct because if you push the system into swap these 'leaky' processes suddenly shrink to a small fraction of there size - unload the system so there is no swap and they stay small but slowly grow over time.

    Well, on my system (linux) the above code will quickly (if the sleep function is removed) eat up 99% of the real memory and all of the swap, but continues to run.

    Sometimes undef stuff helps. Rewriting it into a more functional style will probably work as well if it really matters. It will probably make no difference but in the close code you could make an undef change

    You're right, it doesn't make a difference. But thanks for the advice, I don't have time to rewrite XBase unless I absolutely have to, which it looks like I will...

    tigervamp