Destroy an Object

BlitzMax Forums/BlitzMax Programming/Destroy an Object

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

It's called when the Garbage Collector is cleaning up.

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

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.

Ok, thank it's work fine after use GCCollect()

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.

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.

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