Memory Usage question (detecting leaks)

I found some code somewhere and I'm using it to try and track memory leaks.

My game fires up listeners at the beginning and are not re-called. I think I'm cleaning up, so I'm trying to understand the values returned.

1
2
3
collectgarbage("collect")
    local systemMemory = collectgarbage("count")
    print("**MEMORY** At Start of Game - System Memory " .. systemMemory .. " Texture Memory: " .. system.getInfo("textureMemoryUsed") .. " level " .. level)

According to Lua, the number returned is in Kilobytes. So 256K + 19M texture memory is probably a fairly small footprint.

So now to find out what's not getting collected.

Rob

You can't track memory leaks inside your code. You have to use Xcode Instruments.

I found out why I was having problems with Instruments. You have to use a Development provision profile not a distribution profile.

Now its found 3 leaks in my program, but the information doesn't seem to be exceptionally helpful. I see some are in UIKit, and others in Audio Toolbox.

How do I map this back to Lua/Corona code? When I drill down I get assymbly code but there are no symbols that are any reference back to my Lua code.

Any ideas?

I ran Instruments again tonight and I see there were quite a few leaks coming from _vasprintf_l. I don't see how any of my print's could be leaking unless its a Coronoa/Lua issue. So that leaves my string.format() calls.

I could see where my high score screen might possibly have a problem, but I never loaded the high score screen during my Instruments run, so that leaves code like this:

1
    local enemy = display.newImage(string.format("enemy_%02d.png", enemyId))
views:1183 update:2011/10/3 8:06:12
corona forums © 2003-2011