Destroy an Object

BlitzMax Forums/BlitzMax Programming/Destroy an Object

Eole(Posted 2009) [#1]
Hi !

How can I do to call the Delete method of an object ?

If I do this

type myType
   field a:int

   method new()
     a=1
   end method

   method delete()
     print "type destroy"
   end method
end type

local test:myType = new myType

test =null


The delete method is never call


Nicolas


Htbaa(Posted 2009) [#2]
It's called when the Garbage Collector is cleaning up.

Try adding GCCollect() after your test = Null line.


GfK(Posted 2009) [#3]
What Htbaa said.

GC doesn't clean up continuously, just a couple of times per second. Your test program works but is ending before GC gets around to doing anything.


Eole(Posted 2009) [#4]
Ok, thank it's work fine after use GCCollect()


ziggy(Posted 2009) [#5]
Delete method will be called when the GC really releases the object memory. Take in consideration that if your APP exits BEFORE the GC has cleared all the memory, some objects will never call their delete method.


plash(Posted 2009) [#6]
Take in consideration that if your APP exits BEFORE the GC has cleared all the memory, some objects will never call their delete method.
Right. So don't put anything in your delete method that would be saving some sort of information or anything else outside of the application.

Or you could call GCCollect in your OnEnd function.


Eole(Posted 2009) [#7]
After many try, the Delete method is strangely called in the case of class heritage.

I abandoned the use of Delete, I created my owner delete method

Nicolas