Question about Destructor()

BlitzMax Forums/BlitzMax Programming/Question about Destructor()

Afke(Posted 2012) [#1]
Hi guys,

Delete method is never called when I destroy Type Test.

What is wrong here :)
SuperStrict

Type Test
	Field a:Int
	Field list:TList=New TList
Method New()
	Print "Object Created"
	
	For Local i:Int=0 To 100
		list.AddLast("item_"+i)
	Next
End Method
Method Delete()
	Print "Object Deleted"
End Method
EndType

Local t:Test = New Test
t = Null

GCCollect



Thanks


BladeRunner(Posted 2012) [#2]
The GC will not collect until there is enough stuff to do so. Create some thousand of your objects and it will start working.

Last edited 2012


Afke(Posted 2012) [#3]
Thanks

I thought that GCCollect works instantly . :)


Htbaa(Posted 2012) [#4]
More or less yes, but if this is your entire program then it ends after the G CCollect and it could be well possible that it ends execution before it gets to GCCollect can finish.


ziggy(Posted 2012) [#5]
Deleting objects waist CPU time, so it is only done when it is required. Sometimes it does not get called at all, if the amount of mem to free is not significative (it'll be freed when/if there are enought objects to free that it's worth it).


Afke(Posted 2012) [#6]
Thanks guys for your help