Frustrated with memory management

Good evening all. For the last couple of months, I’ve been working on my first real game project using corona. At first, I was throwing spites left and right and the performance was horrible. I studied the docs and took as much advice as possible on sprite sizes, sprite sheets, etc. Now, the performance is much better, but I have another problem.

In my game, it has a world map similar to Candy Crush, with each level marked by a sprite. The problem is, I have 200 + levels, each with a marker. When I draw them on the map, much memory is used up. I have made the markers as small as possible. When the user selects a level to play, I transition to a new scene, called the level_scene. In the enterScene function, I have the following code:

storyboard.removeAll()

This is supposed to eliminate all the textures in the other views if I am not mistaken. However, the performance of the game in the level_scene is terrible, and I have reason to believe it is because memory is still overloaded from the map scene. In fact, when I limit the number of the markers on the map to 3, the level_scene runs smoothly.

I’ve been running this method every second to check memory consumption:

local function checkMemory()

   collectgarbage( “collect” )

   local memUsage_str = string.format( “MEMORY = %.3f KB”, collectgarbage( “count” ) )

   print( memUsage_str, "TEXTURE = "…(system.getInfo(“textureMemoryUsed”) / (1024 * 1024) ) )

end

Why does the memory consumed by a previous scene affect the current one? Has anyone had a similar issue?

What values are you getting for your print above?  Is it different if you comment out the removeAll() function? 

Rob

Home_Scene = 777kb

Map_Scene = 1221kb

Game_Scene = 1091kb

Then I go back to the map…

Map_Scene = 1445kb

Then back to home…

Home_Scene = 1091kb

Map_Scene = 1445kb

Game_Scene = 1091kb

When I remove removeAll() i gets much worse, so I guess that is working. I think I may be cleaning up my images in the wrong way. Currently, I create new groups and put them inside the main scene group. Do these subgroups get cleaned up when removeAll() is called or should I remove them manually?

That appears to be Lua memory and those numbers are not bad, nor show a problem.  What is your texture memory like it will be a bigger number in MB.

Rob

In the game_scene, it’s 31. In all other scenes, its 25. 

I found the issue. It had nothing to do with memory or textures. I was reading a large file every time I needed it rather than opening it once and saving it as a scene-wide variable, which was really stupid. Sorry for wasting your time, and thanks for trying to help.

I’m just happy you found it.

Rob

Hi gjan011

Please about more detail your solution, i need your solution method for my project.

I create a image file for ipad retina, it resulation is 1440*1432, when i use it, my texture memory is to low. Is it normal?  

Thanks

 Bemole

a 1440 x 1432 image is really a 2048 x 2048 x 4 texture size or 16MB.  That alone isn’t going to be too much memory unless you are trying to load that on an iPhone 3Gs or iPad 1.  But if you have multiple of those running around (unpurged scenes), other large images, you can quickly get up into the 60-100mb app size and that will start stressing the available memory you have. 

Rob

What values are you getting for your print above?  Is it different if you comment out the removeAll() function? 

Rob

Home_Scene = 777kb

Map_Scene = 1221kb

Game_Scene = 1091kb

Then I go back to the map…

Map_Scene = 1445kb

Then back to home…

Home_Scene = 1091kb

Map_Scene = 1445kb

Game_Scene = 1091kb

When I remove removeAll() i gets much worse, so I guess that is working. I think I may be cleaning up my images in the wrong way. Currently, I create new groups and put them inside the main scene group. Do these subgroups get cleaned up when removeAll() is called or should I remove them manually?

That appears to be Lua memory and those numbers are not bad, nor show a problem.  What is your texture memory like it will be a bigger number in MB.

Rob

In the game_scene, it’s 31. In all other scenes, its 25. 

I found the issue. It had nothing to do with memory or textures. I was reading a large file every time I needed it rather than opening it once and saving it as a scene-wide variable, which was really stupid. Sorry for wasting your time, and thanks for trying to help.

I’m just happy you found it.

Rob

Hi gjan011

Please about more detail your solution, i need your solution method for my project.

I create a image file for ipad retina, it resulation is 1440*1432, when i use it, my texture memory is to low. Is it normal?  

Thanks

 Bemole

a 1440 x 1432 image is really a 2048 x 2048 x 4 texture size or 16MB.  That alone isn’t going to be too much memory unless you are trying to load that on an iPhone 3Gs or iPad 1.  But if you have multiple of those running around (unpurged scenes), other large images, you can quickly get up into the 60-100mb app size and that will start stressing the available memory you have. 

Rob