confusing destructor

BlitzMax Forums/BlitzMax Beginners Area/confusing destructor

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Destructors are not guaranteed to be called, simply because the Garbage Collector ( by default ) runs when it wants to and your program may finish before the destructor is called.

Type Ttest
	Method New()
		Print "constructor was called"
	End Method
	
	Method Delete()
		Print "destructor was called"
	End Method
End Type

Local a:Ttest = New Ttest
a = Null
GCCollect


If you force collection as in above, you'll see it gets called. But you should not rely on destructors for the reason I explained above.