Garbage collecting question

BlitzMax Forums/BlitzMax Programming/Garbage collecting question

nawi(Posted 2009) [#1]
If ..
   Local list:Tlist = Createlist()
   ListAddLast(list,obj)
endif

Do I need to clear the list of objects manually to prevent a memory leak?


Gabriel(Posted 2009) [#2]
No. When the list goes out of scope, the objects on it go out of scope and are collected. You probably won't get it to work in a test situation as the GC is a bit funny about local variables which have no scope "depth". IE: A local that's not in a function or any block of code. If you try it in a function, it should demonstrate.

Function TestStuff()
   Local L:TList=New TList
   Local A:Thing=New Thing
   L.AddLast(A)
End Function

Type Thing
   Method Delete()
      DebugLog("I was collected")
   End Method
End Type


TestStuff()
GCCollect()

Delay(1000)



nawi(Posted 2009) [#3]
Thanks.