[chuck-users] Destroying object instances ... unchuck?
gewang at CS.Princeton.EDU
Mon Jan 29 02:44:52 EST 2007
> Is there a way to explicitly destroy object references?
Currently, ChucK is undergoing much development in terms of garbage
collection. In the released version, objects are ref counted, but
not all references are released correctly yet. This means either
structuring code to minimize garbage, or "manually" releasing
references, in order to control memory usage for now.
Someday soonish, ChucK is going to be a (hopefully properly) garbage
collected language, which means the programmer will not have to
manually release objects after use.
> For instance, in a loop, I am creating an array of objects like so:
> Object objects;
> 0 => int count;
> for(0 => int i; i < 4; i++ )
> new Object @=> objects[count];
> Now how would I delete the Object referenced at, say, objects?
In this particular case, by assigning new instances of Object into
objects, the old objects should have been released automatically.
You can also assign 'null' to object references to decrement their
ref counts, and if no other references exist to that object, it will
Also, as you probably know, one can declare arrays of null
references, to reduce redundant/useless instantiations:
// array of null Object references
Object @ objects;
We are still experimenting with various options for garbage
collecting ChucK, and will likely adopt two or three approaches for
initial release/testing, selectable by the programmer. In any case,
we don't expect any syntax-alterations to the language. We will
continue to keep you posted.
More information about the chuck-users