OK, I'm doing some work on making sure that my app isn't leaking memory and I'm finding it a real head-scratcher. For the purposes of explanation I have two main parts - the front-end and the actual game. I'm finding that the front-end is leaking around 100k each time it unloads. It was much more until I decided to add by own object cleanup - the front-end has a large number of sprites in the background which are added to a table and added to the parent sprite (FrontEnd) as they change continually and wanted an easy way to reference them - so I'm removing them from the parent and then nil'ing the table they're held in. This, I think, is part of the problem and a disconnect in my thinking about Lua memory management - I guess when using Objective-C I'm used to having to control it all myself but, not having some release method built in in Lua, you can't do that easily so I'm kind of stumbling around a bit. Would event listeners cause an instance's memory not to be freed up? I'm calling Timer.stopAll() as I'm aware that running timers could stop collection. Following @atilim
's code on the forum I'm calling collectgarbage() 4 times before doing a collectgarbage("count"). But does anybody have any tips here on what to look out for that would cause things not to get released.
Secondly, I'm using a single packed texture for all the artwork. The front-end reports no change to the texture memory usage when it unloads. However, the game itself is reporting a 1mb increase each time it unloads. I am using some TTF text but I'm also using this on the front-end as well. Now I'm trying to think why this could be. I'm using a sprite cache for a lot of images, grabbing the texture regions and keeping them in a global for performance reasons (I've found this quicker than trying to grab texture regions as needed) but there are still areas where they are being grabbed as needed. Does that act of grabbing a texture region actually make an increase in texture memory usage? Is that correct? It's not what I'd expect.
So anyway I'm a bit confused and need to get my thinking straight. I haven't tried the XCode tools yet, I'm trying to see what kind of memory work I can do in Gideros itself first.
Sorry it's a bit of a long, wordy, post. Just want to get my head around Lua's memory management.