I've been thinking that an efficient GC might be a very nice thing to have as part of the scripting language of my game tool that I'm working on.
I was wondering if people think that this scheme is a good idea. It is a variation on reference counting. (Sorry, most folks may find this boring and TOO nerdy, this is probably only interesting to true egg heads... does that make me one?
)
Ok, so to use the scheme in my language, I cannot overload any operators so using the GC's features is actually explicit but pretty simple. It does at least still remove the need to manage memory yourself. Here is the set of keywords that must be used and what they would do:
ref! - store a reference, inc ref counter of the referred obj
ref@ - fetch reference, set "do not clear" flag of that obj
deref - clear reference, dec ref counter of that obj, delete it if the counter reaches 0.
protect - add obj to list of objects not to delete (or mark it with a flag)
release - release an object explicitly so that it can be deleted by the GC. cancels PROTECT.
The last two are needed because in my setup I try to solve the "circular reference" issue by only deleting objects references that are not USED by any code during a GC cycle. however this may not be wanted sometimes (in the case of theoretical "idle" objects... i don't know, such as objects in a different room than the one the player is in) so i have a simple mechanism for preventing that. PROTECT and RELEASE could be recursive so if called on a collection all children would also be affected.
thoughts? ideas?
and most importantly, is it practical?