Ok, that’s an obvious title and this is the second writing of this post, so I’ll keep it short. It’s late.
I thought I was doing cleanup of my display objects by calling removeSelf on their parent group. I was not, however, setting references to them within a table I was using as an array, to nil.
This, eventually, showed that the removeSelf() function actually sets all the display object values and functions back to nil. Go ahead, try it. Create a display object, say an image, print out it’s values. Then call removeSelf() on it and print its values again. Also print references to its functions: print(myDispObj.removeSelf == nil)
You will get nil (or, for the above snippet, true, because it is nil) for everything associated with a display object. However, you will not get a nil object, because you are still holding its reference.
The kicker is that because garbage collection is not always immediate - rarely immediate, in fact - calling removeSelf on it and then printing the display values will still give you something. If you, however, call collectgarbage(“collect”) immediately before printing its values, you’ll see that the display values are immediately set to nil.
Eg:
[lua]local img = display.newImage(“crate.png”)
print(img.removeSelf == nil)
img.removeSelf()
print(img.removeSelf == nil)
collectgarbage(“collect”)
print(img.removeSelf == nil)[/lua]
Run that and you should see that the second print returns false, however the third print returns true.
This may only be useful to me as a record of what not to do, but maybe it can help someone else, too…
Matt. [import]uid: 8271 topic_id: 5312 reply_id: 305312[/import]