Could someone explain how to take a project built in Corona Project Manager (or any text editor) and run it with the Xcode memory leak tools? I’m desperate to find out the cause of my app bogging down. [import]uid: 52127 topic_id: 13489 reply_id: 313489[/import]
- Build your app with Corona SDK and use a “Development” provisioning profile.
- Use any valid method to install the app on a tethered device (I use the XCode organizer). Keep your device tethered.
- Run the “Insturments” app on your Mac and select “Leaks”
- From the drop down of apps find the one you want to run, then click on the red circular “Record” button. It will launch the app on your device. Performance will be horrible with long pauses at times. You will get a sliding graph of leaked memory and a report at the bottom where in Xcode terms its coming from, like UIKit, Audio Mixer, etc.
Combine what you were doing when a leak happened with what little information about where the leak originated and go hunting in your code.
[import]uid: 19626 topic_id: 13489 reply_id: 49540[/import]
Thanks for the detailed response. I got it working with your instructions.
Turns out it’s pretty much useless though. All I know now is that the “Responsible Libraries” are AudioToolbox and UIKit. Not sure how anyone is able to debug memory issues with Corona since everything is obfuscated from us.
Any idea on what issues I should look into if my app plays fine when you first start it, but keeps running slower and slower the longer you play, until finally it just crashes? [import]uid: 52127 topic_id: 13489 reply_id: 49572[/import]
Also, when I run Allocations, the “Live Bytes” never gets larger than 8-10MB, even when it crashes. [import]uid: 52127 topic_id: 13489 reply_id: 49574[/import]
You’re likely to not get much more help on hits. These forums are great, but when it comes to memory management beyond telling you to :removeSelf() and nil everything, there are not many answers here. It’s been a frustrating point for me.
I knew that mine was sound related and I even found a bug that was fixed because the leak was happening in the audio system. But I spent a lot of time checking every object, making sure I wasn’t writing over it and making sure I was freeing it.
You can print your texture memory and call gcinfo() to get the amount of Lua memory (in kBytes) that you’re using. I would check that at the beginning of each round/level where in my mind, I should have the same memory foot print if I’m not leaking. Do a garbage collection at the beginning of the level print the values and see if your memory is growing over time.
There are a lot of things that can leak besides memory. If you have function a that calls function be that calls function c that calls function a (which can happen if you don’t return from your event handler functions) will eventually blow your stack space out from getting too deep.
Having a bunch of timers that don’t get freed up and cancelled can pile up on you too. In my game OmniBlaster, at the beginning of a round, I would do a timer that brings the level boss out after 45 seconds or so. But if I die before the boss came out, I would end up starting a new round and spawn another boss timer, and they start piling up on me.
Make sure you’re not loading the same sound over and over.
[import]uid: 19626 topic_id: 13489 reply_id: 49607[/import]
Thanks for the tips. I’ve been able to clean up a few things. Were you ever able to get to the point where the system memory was the same every time you created a new level? It seems like no matter what I do the system memory always increases by 5-10 kb every time I reload the same level. [import]uid: 52127 topic_id: 13489 reply_id: 50074[/import]
My game doesn’t use Director and for the most part, I’m starting at the same memory. It varies from round to round, but it usually ends up at the same point.
Now I ran leaks against my RSS app I’m building and I’m still not using Director, but the TabView controller from the community code submissions, and I’m leaking 16 bytes of memory whenever I change screens.
I’m not going to worry about trying to track that little bit down. [import]uid: 19626 topic_id: 13489 reply_id: 50086[/import]
I also had memory leaks in an app that caused it to slow down over time.
Finding and correcting the problem was a lot of long hours or trial and error. I ended up implementing EVERYTHING in the following threads.
http://developer.anscamobile.com/code/texture-memory-monitor
http://developer.anscamobile.com/forum/2011/02/28/fspmemory-profiler-swfprofiler-ported-corona
http://developer.anscamobile.com/forum/2011/03/07/potential-serious-memory-leaking-issue
http://jonbeebe.tumblr.com/post/3760389212/proper-group-cleaning-in-corona-script-download
http://jonbeebe.tumblr.com/post/3779340554/group-cleaning-script-updated-to-1-1
http://jonbeebe.tumblr.com/post/2090082695/faster-garbage-collection-with-corona
http://jonbeebe.tumblr.com/post/1444906715/code-optimization-and-memory-leak-prevention
I might have gotten the memory leaks cleaned up faster if I had tried these in a different order. [import]uid: 67839 topic_id: 13489 reply_id: 50115[/import]
OK, so my team is in the same boat. Our Game is running fabulously, until we get around levels 6 or 7, then some things start to slow down. If we start the game at those levels, there’s no slowdown. So it’s not a game resource taxing the FPS, but rather an accumulative issue we’re 99% sure. However, my team has done the fine-tooth-comb clean sweep and have zero memory leaks and we’ve confirmed no residual Listeners/Timers are causing havoc. But we MUST be missing something.
We just updated our SDK to 591.
I can tell you my Game is HEAVY audio intensive, and we’ve read lots around audio issues/leaks. So this makes us nervous and suspicious.
Above someone speaks about running “Instruments App”; not sure what this is referring to?
Secondly, I haven’t used XCode all that much as an “environment” and I would like to run the Corona build on the XCode Sim. But I’m not sure what steps we take to do that? Is there some documentation that runs us through that process of importing our build into XCode? I only use XCode at this point for copying the build over to the device via Organizer. It’s been many many months since I was using XCode to develop in. So any Corona Forum tutorials about this process of importing the build into XCode for purposes of running within their Sim? For one thing, Corona SDK cannot support the Facebook API calls within the SDK Sim, but XCode can - apparently?
Thanks in advance for any tips or links.
FOLLOWUP: Well, duh?!? So the BUILD window for Corona SDK asks if you’re building for DEVICE or Xcode Simulator. So that answers THAT question… the next “real” question I have is - what documentation out there talks about what we can do to determine if our “devices” are running things in the background perhaps impacting performance? There must be a process to look at this aspect of “real world testing devices”. I’m going to get an iPod Touch for testing and keep it clean for this purpose, but if my “real world” devices are showing something different from the SIMs then I want to know what’s going on. I am positive others have already wrestled with this. [Our observation is that the Corona Sim on Windows machines do not exhibit the slowdown we see when we’re on our Macs; additionally you’ll see comments below that the Xcode Sim seems to exacerbate the slowdown compared to Corona Sim.]
ADDITIONAL FOLLOWUP: After running Instruments on the App within the Xcode Sim we were able to confirm as our preliminary analysis indicated, we are suffering no memory leaks. (yay!) However, with each level we are seeing on average a 15% increase in accumulative CPU usage. So this is our problem. Intuitively this leads us to believe we have a residual timer out there (or two). Although we have combed the code repeatedly, this information leads us to believe we’re missing something.
QUESTION1: Trying to confirm that we can run Instruments on a device WHILE it’s tethered to Xcode and get information on the physical device as well? I think we saw that mentioned in a thread somewhere. Can someone confirm for us this is possible? Just curious.
QUESTION2: We’re seeing that the Xcode Sim runs slightly slower than the Corona Sim; I believe that’s consistent with some other feedback we see in threads. Confirm to be true? Is there an explanation that many of us would benefit from as to why this is the case? (just curiosity) [import]uid: 74844 topic_id: 13489 reply_id: 51917[/import]
QUESTION1: Trying to confirm that we can run Instruments on a device WHILE it’s tethered to Xcode and get information on the physical device as well? I think we saw that mentioned in a thread somewhere. Can someone confirm for us this is possible? Just curious.
Answer1: I’ve never run instruments against the XCode simulator. But when I run instruments, I have my phone tethered. You don’t need to have xcode running. First, you have to make sure to do a “Development” provisioning profile so that the debugging information will be there. When you launch instruments and pick leaks, pick your device and pick your app. It will start it, and start collecting data.
QUESTION2: We’re seeing that the Xcode Sim runs slightly slower than the Corona Sim; I believe that’s consistent with some other feedback we see in threads. Confirm to be true? Is there an explanation that many of us would benefit from as to why this is the case? (just curiosity)
I’ve not noticed the XCode sim being slower. But then I don’t use it much.
[import]uid: 19626 topic_id: 13489 reply_id: 51935[/import]