Garbage Collector

BlitzMax Forums/BlitzMax Beginners Area/Garbage Collector

BLaBZ(Posted 2010) [#1]
What is it and what does it do?

Not quite familiar with this coming from B3D


Dreamora(Posted 2010) [#2]
Garbage Collector are a common thing in managed languages (C#, Java, Eiffel).

In such an environment you can only request that an object is created.
The cleanup of the object is done by the GC and happens when no object is holding a reference to said object any longer


BLaBZ(Posted 2010) [#3]
Would I use this to free an objects handle? I want the object to exists still, I just would like to use its handle for another object


Dreamora(Posted 2010) [#4]
you don't use it at all, it works in the background.

you can assign references (typesafe pointers) whereever you want, there is no restriction


Czar Flavius(Posted 2010) [#5]
Not quite familiar with this coming from B3D

Ok in simple talk. In B3D when you create an object using New, you have to remove it using Delete at some point. In BM, this is done automatically. You don't need to worry about deleting objects after use.

Would I use this to free an objects handle?
They are not called "handles" anymore, they are "ordinary" variables. But they work in a similar way. When you want an object's handle (or variable holding its reference, for proper-speak) to be free, you just say MyObject = Null. If the object that MyObject used to be referring to no longer has any other references (or handles), it is deleted automatically.

I want the object to exists still, I just would like to use its handle for another object

Strict
Local handle1:MyType
Local handle2:MyType

handle1 = New MyType
handle2 = handle1
'now both refer to same object

handle1 = Null
'only handle2 refers to the original object

handle1 = New MyType
'both handles refer to unique objects now.

Advice: make sure to use Strict or SuperStrict mode, to increase efficiency of the garbage collector.