Destroying Objects

BlitzMax Forums/BlitzMax Beginners Area/Destroying Objects

ziggy(Posted 2005) [#1]
Is there any Method such as NEW that can be automaticaly invoqued just before an object is destroyed (reference count = 0) ???
If it's not, it should be a great improvement


Michael Reitzenstein(Posted 2005) [#2]
The method Delete( ).


ziggy(Posted 2005) [#3]
Thnxs!!! :)


ImaginaryHuman(Posted 2005) [#4]
Hey, didn't know that :_)


Dreamora(Posted 2005) [#5]
but it isn't guaranteed that it is called on collecting through the garbage collector.


teamonkey(Posted 2005) [#6]
It's guaranteed that it's called, it's just not guaranteed when it's called ;)


Dreamora(Posted 2005) [#7]
what possibilities are there for the when?

Before or after the object is destroyed? ( the later one would be useless and result in feature call on null target ;) )


teamonkey(Posted 2005) [#8]
Delete() will always be called immediately before the object is destroyed - but you can't guarantee when it will be destroyed :)

Actually, that's a bit of a lie. If you can guarantee that the object has no references you know it will be deleted at the next FlushMem, but if you rely on that behaviour one forgotten reference to the object will turn your game into debug hell.