Memory management and display.newImage

Hi,

I need to display one of many full-screen images at any one time, as controlled in separate functions. I’m using global values for their assignment (e.g. background1 = display.newImage("[file.png]") etc.). I’m then controlling their appearance with ‘tranition.to’.

Currently, I’m assigning these global values in the relevant function, and then releasing them (e.g. background1:removeSelf) in the subsequent function that is called.

Is this the most efficient way of doing it? Or would it make no difference if I assigned all the global values (for these many display.newImage’s) first, and then just released them when finished with? (which would result in tidier and more manageable code - if nothing else).

Hope this makes sense.

Thanks in advance.
Dave. [import]uid: 82595 topic_id: 15529 reply_id: 315529[/import]

Using a lot of globals is never ideal but if you have to do it, clean up as soon as you can. [import]uid: 10144 topic_id: 15529 reply_id: 57375[/import]

Thanks Peach. One other question…

As I’m jumping between many functions (to control the flow of my game/app) - once I’ve left a function, I know I won’t need it again. Is there a way for me to release these functions?

In some instances, I’m using the ‘onComplete’ component of the ‘transition.to’ command to jump to the next function once the animation/movement has complete?

Any thoughts? Thanks in advance.
[import]uid: 82595 topic_id: 15529 reply_id: 57449[/import]

Hey there,

Lua/Corona is/are pretty good with managing things like that independently, however you could use [lua]collectgarbage(“collect”)[/lua] if you wish.

Great explanation of it here;
http://lua.gts-stolberg.de/en/Basis.php

Peach :slight_smile: [import]uid: 52491 topic_id: 15529 reply_id: 57458[/import]