Freeing Memory?

BlitzMax Forums/BlitzMax Programming/Freeing Memory?

When you set your TGamePlayScreen to null and remove it from a list (if it's on one) and/or it falls out of scope then the pointer to, for example, m_pTGalaxy:TGalaxy will be deleted. If this is the only reference to that TGalaxy object it will be removed when GC next runs.
However, if it is on a list and you don't remove it from that list you'll still have a reference to it. You'll need to remove it from the list when you delete the object which references it.
Global alllist=CreateList()
Type ttest
  Field t1:ttest1
End Type
Type ttest1
End Type
Graphics 640,480
For x = 0 To 5000
  Cls
  mynew:ttest = New ttest
  mynew.t1:ttest1=New ttest1  
  ListAddLast alllist,mynew.t1
  DrawText  GCMemAlloced(),0,0
'  ListRemove alllist,mynew.t1
  mynew = Null
  DrawText  GCMemAlloced(),0,20
  DrawText x,0,40
  Flip
Next