TList Local scope

BlitzMax Forums/BlitzMax Programming/TList Local scope

tin(Posted 2008) [#1]
ok, here my question,
Missile is created in FireMissile method in SpaceShip TYPE (Local Missile:). after that method FireMissile is finished, isn't that Missile object is deleted? because it's declare Local? and why it's left in GameObjectList:Tlist in global?

Global GameObjectList:TList

Type TMissile Extends TGameObject
    Function Create:TMissile()
        Local Ship::TMissile=New :TMissile
        ListAddLast GameObjectList, Ship       
        Return Ship
    End Function
End Type

Type SpaceShip
   Method FireMissile()
         If MissileDelay<0
     ----->>>>> Local Missile:TMissile=TMissile.Create()
            MissileDelay=10
         End If
    End Method    
End Type 



Dreamora(Posted 2008) [#2]
no it will never be destroyed. Its put into the list, so unless you remove it from the list again it will not die.


Brucey(Posted 2008) [#3]
and why it's left in GameObjectList:Tlist in global

Because you now have a reference to the Object in the TList. As long as there's a reference to it, it will never be Garbage Collected.

Like what Dream said as I was typing this... :-p


N(Posted 2008) [#4]
Because you put it in the linked list. Until you remove it from the linked list, it will never be freed.

I just wanted to be cool.


tin(Posted 2008) [#5]
thanks.
got it.


Schragnasher(Posted 2008) [#6]
to be a bit more explanatory, your only ever dealing with references to objects. so long as there is a reference, the object will still exist. you cannot destroy anything without destroying its references. Its actually quite useful that way.