The dangers of automatic GC mode

BlitzMax Forums/BlitzMax Programming/The dangers of automatic GC mode

Calling GCCollect is best avoided as much a possible, its better IMHO to add a free method to the TFoo type... (modified from your example)

SuperStrict
Framework brl.linkedlist
Import brl.standardio

Type TFoo
	
	Field thing:TThing = New TThing
	
	Method Delete()
		If thing thing.Free()
	EndMethod

	Method Free()
		thing.Free()
		thing=Null
	EndMethod

EndType

Type TThing
	
	Global list:TList = New TList
	Field link:TLink = list.addlast(Self)
	
	Method Free()
		link.remove()
	EndMethod
	
EndType



Local foo:TFoo = New TFoo
'foo.free()				' UNCOMMENT TO FIX
foo=Null
'GCCollect()				' BAD PRACTICE

If TThing.list.count()
	Print "~n"+TThing.list.count()+" item in TThing.list"
	Print "This happens because the GC hasn't collected yet~n"
Else
	Print "~nYAY, TThing.list is empty!~n"
EndIf



But if you really don't want the added api, then adding a GCCollect (before you examine the list) is the only solution.