Don't ask to ask, just ask | |
PerlMonks |
Why bother with the mark and sweep garbage collection on non-embedded interpreter shutdown?by dynamo (Chaplain) |
on Jun 15, 2005 at 22:18 UTC ( [id://467091]=perlmeditation: print w/replies, xml ) | Need Help?? |
Bretheren,
I have read much about perl's garbage collection infrastructure, and I am familiar with the advantages and disadvantages of mark&sweep vs. reference counting. I understand that the reference counting takes care of most of the memory deallocation throughout the program's execution, and that upon shutdown of the interpreter, a full-on mark&sweep gc run is executed, and thus self-referential and circular-referential nodes can be collected and released to the kernel. This makes sense to me in the context of a host program that runs an embedded interpreter, such as apache running a mod_perl system that re-uses modules and would not want to accumulate memory leaks. But for a normal perl program, let's say a simple non-interactive script running from the command line as a seperate process, what benefit is there from doing exhaustive and time-consuming garbage collection just before exiting and after all productive work is done? When a process exits, ALL the memory is released back to the kernel - interpreter memory, program-space memory - all of it. Circular references or not. Isn't this last minute gc just a big waste of time for the cases (outside of persistent runtime environments) where any garbage would be collected? Or am I missing something? Your enlightenment would be most appreciated.
Thanks,
Back to
Meditations
|
|