[Melbourne-pm] Perl garbage collection behaviour
scottp at dd.com.au
Tue Aug 23 23:43:30 PDT 2005
On 24/08/2005, at 16:12, Harley Mackenzie wrote:
> I have an application that I have developed that regularly polls a
> database table for new records, sleeps for most of the time and
> otherwise periodically generates some reports and faxes. The
> application works fine except for the memory behaviour, wheret 8KB
> of memory is used up for each database poll (running on Windows
> Server 2003) as reported by Windows task manager, with the memory
> requirements starting out at about 5 KB and over a couple of days
> eventually exhausting all of the available virtual memory and
> causing mayhem on the server.
> I initially suspected a circular reference in my Perl objects,
> except for the fact that if I click on the application that is
> usually running in a minimised state at the bottom of the screen,
> and bring it to the foreground, and then minimise again, something
> kicks off the garbage collection and it then reduces to about 5KB
> and starts the memory accumulation thing all over again.
> As this is a remote server at a client location this is pretty
> inconvenient and has resulted in some nasty out of hours phone calls.
> Am I correct in assuming that there cant be circular references
> preventing the reclamation of memory as it reclaims the memroy when
> the application comes to the foreground?
> Why is this bizarre behaviour occuring at all with the garbage
> collection? Is it because it is in a sleep state for most of the time?
It would seem unlikely. My guess is that you are not releasing data -
or more accurately, some code somewhere in a module somewhere is not
For example, you often find modules keeping references to themselves
or other places - which means that reference count is up for that
variable. Next time, when you release the previous state, you may not
have released the reference to itself.
> Can I initate a garbage collection in the program itself?
No, it is out of your hands.
You could use Devel::Size to look at what is going on.
Hope you get rid of your niggle - hopefully it is not in something
you have no control over.
Of course it could always be a bug in Perl - but I would assume first
that it is your own code - and then a module - and only then perl :-)
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 186 bytes
Desc: This is a digitally signed message part
Url : http://mail.pm.org/pipermail/melbourne-pm/attachments/20050824/a3d52886/PGP.bin
More information about the Melbourne-pm