5b. If I have just a few sound effects in my app that are used all around, can’t they simply live in the global scope of the app? (If I, on the other hand, had a large set of audio files in scene A, and a different large set of audio files in scene B, I would definitely see the need for deallocating audio after each scene).
Correct. I would go so far to say that even if you have a long clip that you use frequently, load it once in some form of global scope and keep it. You would probably pay a bigger performance penalty disposing and reloading it. But if you have sounds unique to a scene and you won’t be back there for a while (or ever) dispose them.
6. In the following code, do I need to nil both variables, or just one of them to cause deallocation?
Yes you must. I conducted a simple test using a variant of your code:
local a = display.newCircle(0,0,100)
local b = a
display:remove(a)
a = nil
print(b)
And this was printed:
2013-01-15 18:20:35.333 Corona Simulator[465:707] table: 0x1007dda40
So clearly B is holding onto the pointer and the garbage collector will think you are still retaining this memory and not de-allocate it.
- Reply #1, Question 1: When removing timers, transitions, audio, and runtime listeners, like you said, do you also have to set all these to nil?
Timers, yes. Transitions, if you save a reference to them, then yes you do. In other words:
myTrans = transition.to(a, {time=500, x=100, y=100, onComplete = checkit})
myTrans will have a reference to the transition when your checkit() function runs, but the transition is over, so there is nothing to cancel so you should nil the pointer. If you cancel the transition, you are still left with a value in the pointer, and you need to nil that as well.
As for Runtime listeners, I don’t believe there is anything you can nil as you don’t ever get a pointer back from any of the add listener functions.
- Reply #1, Question 1: How are transitions and audio with “onComplete” are different from those who don’t have “onComplete”?
With regards to memory, I don’t believe there are any.
- Reply #1, Question 1: You wrote “Anything that’s calling back to a function defined in your scene that references any of your display objects.” Could you give a concrete code example showing what you mean here?
I’m not sure I would have all of them in memory. But as an example, you call network.download() to fetch a photo from Flickr and you give it a call back to then create the display object for it and shove it into your scene’s view. Before that photo downloads, your user navigates away and you purge the scene. That callback function is still active and the system will call that function and try to execute the code. If that function doesn’t exist or the group you’re putting the object into doesn’t exist you can expect a SIGSEGV segment violation or bus error crash.
- Question 7 (new): Widgets created with widget.newSomething() and added to a group, will they be completely deallocated when their parent group is deleted, or do they need some extra attention, widgets being a special type of object?
They should be completely dealocated just like a display.newImageRect() would be. [import]uid: 199310 topic_id: 34463 reply_id: 139092[/import]