Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Circular references and Garbage collection.

by dws (Chancellor)
on Aug 03, 2002 at 05:38 UTC ( [id://187302]=note: print w/replies, xml ) Need Help??


in reply to Circular references and Garbage collection.

A former college professor of mine and I were discussing memory leaks and garbage collection in various scripting languages the other day, and he asked me how this issue was handled in perl ...

You may already have background in this, though for the benefit of those reading on...

There are two principle approaches to memory management. One is to keep reference counts on objects, freeing the object when the count reaches zero. It's more work up front, but memory is freed promptly. One downside is that self-referential structures never reach zero reference counts, and hence are never freed. Perl5 uses this approach.

The second scheme is to periodically sweep through memory, tracing out objects that are reachable through known starting points (e.g., global variables, stack frames), and freeing anything that isn't reachable. There's ongoing overhead, but garbage collection can take noticeable time (though there are many clever optimizations that can make this approach run quickly). Self referential structures that are not otherwise reachable do get freed. Most Java implementations use this approach.

  • Comment on Re: Circular references and Garbage collection.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://187302]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-20 01:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found