newImage performance

Hi all,

I have a game where I created classes representing enemies. Each enemy has graphics and animations. I’m using graphics.newImageSheet for better performance. The question is:

I read that Corona caches files loaded via display.newImage so when I load the same file once again Corona uses its copy from memory.

  1. Does this behaviour is the same in case of graphics.newImageSheet??

  2. What if I call local a = display.newImage(“file.png”) and then I call a = nil and then I call local b = display.newImage(“file.png”). How long file.png is kept in memory? Does second call of newImage load file from memory or as a new file from file?

Many thanks in advance.

m.
[import]uid: 67745 topic_id: 33197 reply_id: 333197[/import]

Hello,

  1. As far as I know, when you load an image sheet, the sheet occupies its space in texture memory (rounding up to next highest power-of-2 size). But once it’s there, pulling images from it is very fast, and shouldn’t take more texture memory. This is why it’s most efficient to use image sheets instead of individual files.

  2. The images should remain in memory until you clear them out. There might be some underlying method that clears out the cache if, and only if, you are approaching the texture memory limit… in which case, it will likely clear the cache before it crashes the app from memory overload.

My suggestion: Make sure you are clearing out images when you can, if they won’t be used again. Use image sheets for everything. Use png files and save them to the most efficient color depth you can without sacrificing too much quality. And, for testing, build a listener that warns you if you’re getting near to memory overload.

Brent [import]uid: 9747 topic_id: 33197 reply_id: 131890[/import]

The image will only be removed from memory when the following series of events occur:

  1. you call either removeSelf or display.remove on the image
  2. you set the image to nil
  3. lua’s garbage collector kicks in, either automatically or via an explicit call to

collectgarbage( "collect" ) [import]uid: 84637 topic_id: 33197 reply_id: 131918[/import]

Hello,

  1. As far as I know, when you load an image sheet, the sheet occupies its space in texture memory (rounding up to next highest power-of-2 size). But once it’s there, pulling images from it is very fast, and shouldn’t take more texture memory. This is why it’s most efficient to use image sheets instead of individual files.

  2. The images should remain in memory until you clear them out. There might be some underlying method that clears out the cache if, and only if, you are approaching the texture memory limit… in which case, it will likely clear the cache before it crashes the app from memory overload.

My suggestion: Make sure you are clearing out images when you can, if they won’t be used again. Use image sheets for everything. Use png files and save them to the most efficient color depth you can without sacrificing too much quality. And, for testing, build a listener that warns you if you’re getting near to memory overload.

Brent [import]uid: 9747 topic_id: 33197 reply_id: 131890[/import]

The image will only be removed from memory when the following series of events occur:

  1. you call either removeSelf or display.remove on the image
  2. you set the image to nil
  3. lua’s garbage collector kicks in, either automatically or via an explicit call to

collectgarbage( "collect" ) [import]uid: 84637 topic_id: 33197 reply_id: 131918[/import]