Haven't got good way to go through type instances

BlitzMax Forums/BlitzMax Programming/Haven't got good way to go through type instances

JoshK(Posted 2006) [#1]
I am trying to figure out the best way to go through all the instances of a type. You can add them to a list in the New() method, but you have to create a special method to remove them from the list. One of the cool things about BMX is you can just delete objects by saying a=null, but now you have to write two lines just to delete an object:
a.destroy()
a=null

Or you can create a new function:
Function DeleteThing(a:thing)
a.destroy()
a=null

This is no good.

There must be a more efficient way to do this.


FlameDuck(Posted 2006) [#2]
You don't have to go 'a=null'. You just have to eliminate all references. In the case of adding it to a list, it is sufficient to remove the object from the list, if it is the last reference to the object in question, the object is automatically garbage collected next time the GC is invoked.

Local myList:TList = New TList
myList.addLast(Thing.Create("whatever"))
' the object is now added to the List collection.
myList.RemoveFirst()
' remove the first object from the list - it will be garbage collected if it is orphaned.