I'm stuck with a problem for some time now and I would like to know if anyone can help. I'm developing an IOS app (iPad) using a main navigation controller and a lot of UIImage. After using the application for a while, the app get killed for Low Memory (not in a particular View) but by checking the iPad log, I don't always see a Low Memory Warning (sometimes I do, sometimes I do not). Even when I receive one, it's just "Low Memory Warning received" but I never get "Level 1" or "Level 2".
By using the Leak instrument from xCode, I couldn't find any leaks.
Can anyone help ?
A memory warning is sent as a notification, so it'll be queued up on the runloop for dispatch as soon as an opportunity arises. If you were to write a (deliberately broken) loop like:
while(1)
{
NSString *newString = [NSString string];
}
Then eventually your app would be killed due to low memory but at no opportunity would it be in a position to receive a low memory warning.
If you're being killed due to low memory without receiving a warning then you've probably creating a memory bottleneck for yourself somewhere, likely you have some sort of loop that leaves a lot of things in the autorelease pool — so, if you get all the way through the loop then the temporary objects vanish and hence have no long-term footprint, but they're accumulating all the time you remain in the loop.
To avoid that sort of situation you want to look at nesting inner parts of the loop in their own NSAutoreleasePool
s. For example, this loop:
while(1)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *newString = [NSString string];
[pool drain]; // stylistically preferred to release, but equivalent
// in reference counted environments
}
Will continue forever but won't ever trigger a low memory condition.
You can also try for memory leak, Apple's Xcode development environment provide a tools for memory leak detection, the easiest way to run it is straight from
Xcode: 1.Product -> 2.Start with Performance Tool(Profiler) -> 3.From instrument select Leaks.
It seems very good at detecting memory leaks, and easy to figure out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With