Garbage Collector
Artur 'Revinor' Biesiadowski
abies at pg.gda.pl
Thu Mar 20 21:09:49 CET 1997
Patch is at
http://www.pg.gda.pl/~abies/mudpp/patches/art026a.dif
(Fusion - I sent it by mail)
NOTE: it is not complete work ! It is only glimpse at my work to keep you
up to date, allow to flame me for bad constructs and share ideas.
It adds automatic garbage collector to mud++.
How this work:
Some of the classes now inherit from VMObject (VirtualMachineObject)
(this include MudObject, Affect, Exit, Repop and some more)
Every instance has it own private reference counter. When we put pointer
to it in some table (for example LList) we have to increase counter by one
( obj->getHandle() ). If we dereference it somewhen later just reduce counter
by obj->freeHandle(). This apply only to direct pointer handling, as I have
already put most needed calls to top-level funs like rmObjInv() (as opposed
to inv.remove(obj) )
No more delete - just remember to dereference objects correctly and GC
will take care of this later.
GC keeps list of all VMObjects and when it is fired up it scans list for
objects with 0 count. When such objects is spotted it is deleted.
NOTE: this desing of GC is not good for multithreaded environement.
I'm not sure how to solve this - maybe we will need separate GC for each tread?
Neverless, it is future.
Why we need GC ?
It is NOT made to make life easier, but to make some otherwise impossible
things doable. True functionality of GC will show up in VM environement - we
will be able to operate on VM variables without fear that object will be deleted
during some wait/sleep statement.
For now GC is infant, it has many bugs with referencing/dereferencing
(at least one in shellpcs), and it will crash when you will allocate too many
objects (I'm fixing it at the moment).
If you want to play with it there are two commands (besides gdb:)
gcdump - dumps GC stack to logfile (in format type_of_object : count )
gcrun - delete items with 0 reference count
(Hint: your items and goblin + his items are at end of dump)
I'm working hard to correct this and later I will start to port/rewrite
my old Virtual Machine and MudAsm.
I also have to put String, LList, Array and Hashtable to GC - but they will
be handled in other way (or not - I'm not sure)
OK, that was long, enough :)
If you have any questions ask. (I will have to write some doc about this :(
Or maybe you are just totally against GC ? It would save me some work :)
Artur
More information about the mud-dev-archive
mailing list