Memory Leaks -- Possible Corona Bug

I'm trying to use Instruments to track down memory leaks and I see one that happens after the the Default.png goes away but before my menu loads.

At that point, I've just initialized my variables, and set up my background and started my event listeners.

So I took some brute debugging techniques and started commenting out things to make the initial leak go away. And I pretty much commented out the entire program and I still get the leak. In fact it reports four leaks, 3 in UI Kit which are small. Then a 512 byte leak that appears to come from Audio.

Is that leak to be expected? Is it going to cause problems with the review process?

How can I know what are my leaks vs. Corona or Lua leaks? Is there a good guide to using Instruments somewhere in case I'm interpreting it wrong?

Is there some debug options for Corona that keeps symbols around to give me a better hint on where my problems are?

Thanks
Rob

How do use setup your project in Corona / Instruments so that Instruments can be used?

The only way I could get it to work was to build with a development provision instead of the Ad Hoc provision.

But Instruments pretty much reports assymbly code and hex memory offsets and the top level api responsible. I'd like to know how others are using it.

Hi Rob
My instruments leak recording reports exactly the same leaks... so I guess
it comes from the corona framework. Did you figure out the problem???

Well for the initial leak, I ended up building a project with an empty main.lua file and it still leaked. So at that point, I gave up on tracking that one down.

As for the rest of the leaks I just played the game over and over to try and see a pattern to the leaks. The big ones all seemed audio related. There were a few in vfsprintf and a few in UIKit. That's about all the useful information I could get from Instruments. Its extra annoying that the game stops for Instruments to gather information then feels like it jumps forward and its hard to get a feel for when the leak actually occurs.

I stumbled upon mine quite by accident. I had read every function, traced execution the best I could to make sure I was clearing everything that could be allocation based and was still leaking. I turned my audio off through my game settings and suddenly no leaks.. zero.. zilch.

So I started commenting out stuff until I traced it to audio.play(). Knowing that it only happens sometimes and not every time I played something, I put a print statement in to see what channel it was using. That section of code should never have more than 17 simultaneous sounds playing but I was seeing channel numbers skipping and frequently getting to the max channels.

So I did two things: I edited all my sounds to make the mono 11Khz and trimmed any excess dead space from their ends so they would play as fast as they possibly could.

I reserved 5 channels for other effects (background music, etc.) and I suspect that there is a bug in audio.play() that is ignoring that channels have been reserved and when it gets near the channel limit it leaks. Instead of letting audio.play() find its own channel, I now use the API call to get an available channel and if its over 25, I abort playing that sound. The user wont miss an explosion or two if 4 or 5 others are going off.

Thanks Rob
Instruments tells me I have a leak in the AudioToolBox library.
I did a search on this and apparently this is a known problem. So the problem is not corona or us leaking, but apples framework. I wonder if apple will reject apps because of their own leaks...

I doubt that initial leak will be a problem. Something that leaks once and never again really doesn't cause problems. Its kind of like malloc'ing memory and never using it.

What they are looking for I suspect (I'm a first timer at iPhone apps, but have been programming for 30 years) are continuous leaks that over time continue to consume more and more memory. So leaking 1Kbytes every 30 seconds would be a problem.

I sent my game in with a leak, but I leaked under 512 bytes in over 15 minutes of play time. In an 11mb game, that's inconsequential (I hope!)

Rob, what was the result of Apple reviewing your App with that initial leak/malloc of inconsequential (relatively small) memory? Did you get it through Apple or did they say anything?

Apple has never complained about memory leaks in my apps. I think they know about the audio mixer one, and its a one time hit, so its not a problem since it doesn't build up over time.

views:1533 update:2011/9/26 8:07:09
corona forums © 2003-2011