Garbage collector singleton. More...
#include <GC.h>
Public Types | |
typedef std::map< std::string, unsigned int > | CollectablesCount |
Public Member Functions | |
void | addCollectable (const GcResource *item) |
Add an heap object to the list of managed collectables. | |
void | fuzzyCollect () |
Run the collector, if worth it. | |
void | runCycle () |
Run the collection cycle. | |
void | countCollectables (CollectablesCount &count) const |
Count collectables. | |
Static Public Member Functions | |
static GC & | init (GcRoot &r) |
Init the singleton instance using the given GcRoot. | |
static void | cleanup () |
static GC & | get () |
Get the singleton. |
Garbage collector singleton.
Instances of this class ( you' only use one, the singleton ) manage a list of heap pointers (collectables) deleting them when no more needed/reachable.
Reachability of them is detected starting from a list of "root" containers each one expected to provide a function to return all reachable object.
Each "collectable" objects is also expected to be a container itself.
typedef std::map<std::string, unsigned int> gnash::GC::CollectablesCount |
void gnash::GC::addCollectable | ( | const GcResource * | item | ) | [inline] |
Add an heap object to the list of managed collectables.
The given object is expected not to be already in the list. Failing to do so would just decrease performances but might not be a problem. Anyway, an assertion will fail if adding an object twice.
PRECONDITIONS:
item | The item to be managed by this collector. Can't be NULL. The caller gives up ownerhip of it, which will only be deleted by this GC. |
References _, and gnash::GcResource::isReachable().
void gnash::GC::cleanup | ( | ) | [static] |
Delete the singleton. You'll need to call init() again after this call, if you want to use the singleton. See init(GcRoot&)
Referenced by gnash::clear().
void gnash::GC::countCollectables | ( | CollectablesCount & | count | ) | const |
Count collectables.
void gnash::GC::fuzzyCollect | ( | ) | [inline] |
static GC& gnash::GC::get | ( | ) | [inline, static] |
Get the singleton.
An assertion will fail if the GC has not been initialized yet. See init(GcRoot&).
Referenced by gnash::clear().
void gnash::GC::runCycle | ( | ) |
Run the collection cycle.
Find all reachable collectables, destroy all the others.