MPMoviePlayerController Thread lock problem - Iphone development - iphone

My app main thread is displaying a movie at the beginning , while other thread are doing background tasks.
Some however, are using PerformSelectorInMainThread to do some stuff.
What happens is that sometimes the movie just get stuck indefinitely , sometimes not , and sometimes get free after a couple seconds.
I'm trying to debug it, however when I'm pausing XCode while the app is stuck all I see is assembly code and I can't really understand anything from it. (I guess something like "symbols" on windows would be cool)
Is there a way to analyze more thoroughly what is running on the main thread and might stuck my video while it's playing ?
Moreover, how come the video get stuck anyway, if i'm playing a video from the main thread while other thread calls PerformSelectorInMainThread , what is really happening (I assumed it would add the selector as an event but won't disturb the movie from playing till the end) ?
Thanks for your help!!

Have you tried using Shark (one of the Instruments tools) to analyze samples?
When things are getting "stuck", it likely means the CPU is churning. Shark samples the CPU every so often (well, in human terms, VERY frequently) during a short burst (I would keep it under 5-10 seconds) and tells you what percentage of the time the CPU is spending on what tasks.
It does exactly what you mention - reverse engineers all the assembly code to look more like the debugger (well, not 100%, but enough).
That would be the first step - identifying the processor-heavy task that your performSelectorOnMainThread: code is calling that causes the video to gum up. Then, once you know what it is - the answer will either be obvious - or you'll have to change your architecture :)

Related

My iOS app runs REALLY slow on iOS 5, what could it be?

Ok, I have a simple reader app that I've had on the store for a while, and it works great. I have a sqlite db of content and I use fmdb to talk to it. I load up my text and display it in a UIWebView. Pretty simple stuff.
When iOS 5 went live, I started getting emails about the app not running right. Sure enough, it is running VERY slow. I have a UISegmentedControl to toggle between chapters, it literally freezes the UI for 10 seconds before it does anything. There are a few other instances where this is the case.
What is going on? The app still works technically, but it is just so slow it is unusable. Has anyone else seen this? Does anybody have any ideas as to what might be going on?
You should run your application under Instruments and let it tell where the program is spending most of its time. The time sampling tool should give you breakdown of the methods which are consuming the most number of samples for a given run.

iPhone camera application running fine in iPhone but crashing in iPod

i made an iPhone app that uses camera. It works fine in iPhone, no memory warnings at all. It is also running on iPod touch 4G but gives memory warnings and crashes after some time after getting level 2 warning.
If someone can point me the possible reason for this. Thanks.
The only way you are going to fix this is by being able to debug it on the device. I wrote this blog to explain how to debug EXC_BAD_ACCESS, which is what I assume you are getting
http://loufranco.com/blog/files/Understanding-EXC_BAD_ACCESS.html
The simplest things to do:
Run a Build and Analyze and fix every problem it finds (or at least rewrite it so that B&A doesn't think it's a problem) -- Having a clean B&A is a really good way to making sure you catch these problems early
Turn on Zombies and run your program -- this makes the last release sent to an object turn it into a zombie rather than dealloc it. Your program will leak tons of memory, but if you ever send a message to a zombie it will stop right there and you will see a bug that you need to fix, because in your real version, that would be a crash (sending a message to a dealloced object).
More techniques described at the link
It crashes on a specific operation or randomly?
if randomly,
use instrument to check your memory leaks and memory usage. It's hard to figure out where the problem lies in without going through all your app.

Small application gets "didReceiveMemoryWarning" right after start

Often, when a lot of applications were opened before my application I get "didReceiveMemoryWarning" and then, after a while iOS usually closes my application.
This is actually become a noticeable problem.
I have read so much so much consider to "didReceiveMemoryWarning" for the last few days. Including posts here. Unfortunately no solution found.
I know that I have to release any memory on this warning and bla-bla-bla…
The problem is that right after application start there is nothing to release. I have one UIViewControlled in memory with AdMob 4.0.2 banner and one own container that serves application data - which is a few records in NSMuttableArray.
Right after start my application takes 1.3 Mb – according to Instruments and at this initial state my application was not working and I definately know no memory leaks.
What is wrong?
I see that some of the heavy games can be started with no problems, but in the same time my application in this case gets "didReceiveMemoryWarning" and is closed.
Is there a way work in normal way in this situation.
Is there some tricks?
Thanks in advance for your suggestions.
Where are you allocating the NSMUtableArray? I think it's being allocated often! (Just a probability...) Do you releasing the NSMutableArray?

iOS Development: What are some ways I can troubleshoot a lag issue in my game that occurs 15 - 30 minutes after playing it?

I'm building an iOS puzzle game to become familiar with the platform and a few of my testers are noticing a severe lag issue that occurs intermittently about 15 to 30 minutes after playing it and the lag doesn't appear to be associated with any specific part of the game. I've tested the app using the Leaks instrument and havent found any leaks yet.
What are some things that would cause a game to instantly begin to lag after playing it for a while?
What are some methods/tools I could use to troubleshoot the lag?
Thanks so much for your wisdom!
UPDATE: As a new iOS developer, I was under the impression that the Leaks instrument would report at least most of my memory leaks, so I was very comfortable believing my app was managing memory properly when no leaks were reported. Not the case! After following a few of the suggestions posted here, I watched a few videos on how to use the Allocations instrument and found that my app was losing a TON of memory over time and, after spending about two hours walking through ALL my code and fixing memory-related code, my game is no longer lagging or reporting any lost memory or memory leaks. Thanks, all!
The main thing would probably be a memory warning, which would in turn cause a bunch of game assets possibly to be freed all at once...
Instead of leaks, the place to start is the ObjectAlloc tool. Leaks only shows you memory used your application already knows about. ObjectAlloc shows you the total memory used, and the real issue would be seeing the graph of memory used climb over time.
Lastly, I would try to get the game into that state while using the TimeProfiler instrument, so that you could see what kinds of operations took up a lot of time suddenly when the game slowed down. You have to do that on device, it will not tell you what is really going on using the simulator.
check to see if you are getting a memory warning. also, try using the heap shot tool in instruments, as something could be holding on to a reference, and stopping objects from deallocating, this doesnt show up as a standard leak.
i would definitely have a look at the object allocation tool, and keep an eye on objects still living.
if you haven't used instruments much, I think apple have some videos up on the dev site going through them.
Are you using leaks with the simulator or with an actual phone? I have found the simulator to have different results than a phone when running leaks. Based on your description it sounds like you have some leaks occurring.
I have had some similar feedbacks while battery runs low. So, you can check, does issue reproduce when device is powered, or not.
Also, do you use openGL in your game? I'm asking because i've observed some lags with first-time appeared textures drawing, although these textures were previously preloaded and cached.
And last question, what devices your testers are working with?
LEAKS are NOT the same as excessive memory allocation.
It sounds like you are just not releasing things that don't need to be around anymore and you're maxing out on memory and chunking.
Check your allocations and keep an eye on what keeps expanding when it shouldn't.

How to detect memory leak / battery drain in an iPhone app

I'm afraid I introduced a memory leak or something to version 1.2 of my iPhone app. When I use 1.2 version I notice that my battery drains a lot quicker then with 1.1 version. For comparison, with 1.1 version the battery would last whole day and still have plenty of juice in the evening but with 1.2 I find that I have to plug it in mid afternoon.
Would a memory leak (or a lot of them) cause an increased battery drainage, or do I have something else going on?
The only interesting thing my app uses is AVAudioPlayer class to play some caf audio files. Other than that it's just couple of views with a table view.
I do call AudioSessionSetAcvie(false) in my applicationWillTerminate method, so I don't think it's the audio session that's causing this. I don't have to have my app active for the battery to get drained. It's enough to use it for a while and then exit. So I'm pretty sure I'm leaving something behind, I'm just not sure what.
I tried playing with Instruments tool, but it looks like you can't used with the app running on the device (for some reason my app stopped working in the Simulator)
Any ideas on how to go about finding what's causing the battery to drain?
Memory leaks will not cause increased battery usage. However, if a memory leak persists, eventually you will get a memory warning, and if you can't clean up enough memory, your application will be killed.
Increased battery utilization usually means something is causing your code to continue running. The best way to tackle this problem is to run your application under Instruments (with Sampler probably) and let it sit there in the state that you're confident it usually runs the battery down. Inspect the results of Sampler, and if you have code running, you'll be able to see the stack trace for it.
Hopefully once you've located what code is running, it will become apparent how to stop it.
Memory leaks won't cause increased battery usage, as Nilobject says.
I would try commenting out various areas of functionality, one at a time, to try to narrow down the area that is causing the problem. In your case, the first thing to try is obviously to remove the audio. If, once you've done that, battery usage is back to normal, you know where to look more deeply.
(for some reason my app stopped working in the Simulator)
I would fix that and use instruments to fix the performance bug. It's never a good idea to fix the difficult defect and leave the easy one.