Difference Betwen object = nil AND then object:removeSelf(). Why want just =nil work ?

I have code to “destroy” a ball
theBall = nil once it hits another object.
but it just drops like through the platform and game play area.
but if I use the below code, it get "destroyed " just as I thought doing = nil would.
if theBall ~= nil then
theBall:removeSelf()
end
any technical reason why this happens ?

Im using the removeself code and it works, I just wanna know why the object=nil
does not work ?

theBall has a body of dynamic.
the platform has a body of static.
[import]uid: 11094 topic_id: 18481 reply_id: 318481[/import]

Could be totally wrong about this…but removeSelf() (as listed in the API docs) only removes the display object (hence it’s a display.* command). When you removeSelf() there is still a leftover lua table but it seems functionally a spare appendage at that point. If you nil first the descriptive data is gone but I guess the hooks remain?

If you really want to wipe something without any kind of lingering memory, you need to do removeSelf() and then nil, I suspect…

[import]uid: 41884 topic_id: 18481 reply_id: 70877[/import]

funny yes!!!

i set object = nil AND
put it in “debug” mode.
THEN I see the object just drop.

but i removeself() on object and it dissappears from “debug” mode.

but yes, I did I quick print(type(object)) debug to console
and the object was indeed showing a ‘table’

so I did exactly and it “wiped” it clean(i.e. set object to nil) as well as remove remove self.

I’m finding printing out the type(object) to be really useful. I use a programming style
of DO one line of code, SAVE file and RUN in simulator. IT works for me.

[import]uid: 11094 topic_id: 18481 reply_id: 70886[/import]

Cuz nil clear remove from memory in Obj-C :slight_smile: [import]uid: 12704 topic_id: 18481 reply_id: 70890[/import]

Richard is spot on.

HOWEVER - you don’t need to actually say ball = nil if you don’t wish to as Corona takes care of that after you call removeSelf(). (Although it is a good habit to get into, IMHO.)

Peach :slight_smile: [import]uid: 52491 topic_id: 18481 reply_id: 70950[/import]