Will iOS app's memory leak leverage any vulnerability? - ios

I have google for this question, and found this slide.
Is that true?

Of course memory leaks can result in your application behaving badly and eventually crashing. This is why you should manage memory carefully (advancing to ARC will probably improve memory leak issues) and also don't forget that you get a chance to clean up when you get memory warnings (via didReceiveMemoryWarning in UIViewController class)

Yes it is. Since your device needs memory to "fuel" other applications, eventually your app will get killed. That's why people use instruments, it's not just because it's a best practise. :)

Related

didReceiveMemoryWarning: what type of memory?

I have a base cordova app, with some objective-c code around cordova's framework. Sometimes I've didReceiveMemoryWarning notification, but I don't understand if the problem is the javascript inside the UIWebView or other.
The documentation says:
Your app never calls this method directly. Instead, this method is called when the system determines that the amount of available memory is low.
But my question is: what type of memory?
RAM? Heap allocations? Something else?
RAM, it is for RAM, if your app consuming more memory without realising it, and no memory to remain to process any more thread then, this didreceivememorywarning get called by system.
You should profile your app with Instruments and you'll get a better picture of what's consuming memory.
The memory issue represents to RAM, generally we are creating the app using different objects, and these objects take some memory to process the required task. If we aware about them we can easily manage the memory but sometimes for beginners it is not managable to debug the memory, and didReceiveMemoryWarning occured. We can diagnose or debug this issue by instruments.

How come memory leaks happen on IOS when ARC is used?

In my IOS app, I used automatic reference counting mechanism, but I still get bad memory access errors and bunch of memory leaks? Can someone inform me on the topic?

iOS, check if the app crashes because of lack of memory

How can I make sure that reason of crashes is lack of memory?
Is there anything specific in crash log?
Maybe I have to use some tools or libraries?
UPDATE: my app uses lot of memory and receives memory warnings. It's very difficult to reduce memory usage. It crashes because of memory warnings time to time. But I want to make sure that it doesn't crash because of other reasons.
So how can I check the reason of app crash (it receives lots of memory warnings every time)
UPDATE2: Application has lots of 3D graphics and complex UI that takes lots of memory for textures. Customer doesn't want to make any kind of "loading..." pauses. If I unload invisible textures in background I can't get smooth animations.
So I just need to detect is there any crash reasons except memory.
At least you could implement the method
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
in your app delegate, and put a log to see if this indeed you are going through it before crashing.
Product -> Profile -> leak is a possible method to check memory leak. Allocations will show the total memory being used, and leaks will show leaks due to not releasing.
how-to-debug-memory-leaks-with-xcode-and-instruments-tutorial
that is a useful tutorial
You can use Apple's Instruments Tool to profile various things such as memory usage. This tool is bundled together with Xcode.

iOS : ARC, not freeing memory

I've kind of a weird issue with my iOS app.
after a while my app goes low in memory so memory warning, everything seems to be fine, but when I check the memory usage I noticed that all the calls to viewDidUnload didn't free up lot of memory, so after a few click in my app, it goes again in memory warning, everything seems to be fine again, but not a lot a memory have been released, so it goes again in memory warning faster, and then it crash (after the third memory warning most of the time). this crash is random : app freeze, app leaves, my debugger says app paused, but no bad access or sigbort, no zombies.
my guess is that memory warning can't free up enough memory has it should.
(I checked all my viewDidUnload and make nil every objects that are allocated in viewDidLoad)
Any help will be usefull !
thanks a lot.
So I managed to work with my issue.
I wrote "-(void) dealloc" methode in all my controllers and check if I enter in it as I should. (on pop controller, dissmiss etc..)
Every time it didn't, I do step by step in the controller to see what was retaining my controller from beeing dealloc.
most of the time it was some property that was not in "unsafe_unretained"
delegate that was in "ASSIGN" (and should not be in assign but in unsafe_unretained)
(heritage from non-ARC project...)
I also had some strange controller with XIB that was not deallocated even if empty.
I rebuild new one step by step with copy/paste and finaly with exactly the same code, the new controller was released, with no visible difference between then !!! gnneee
at least I know how to debug that kind issues now...
I don't think there's any way to give a specific answer without more data so the best I can do is suggest that you stop guessing what might be happening with your app and learn how to measure what is actually going on. Run your app under Instruments and you'll be able to check for leaks and also actually see what classes are responsible for the most of your application's memory footprint.
You should make sure you know how to use both the Leaks instrument to identify leaked object but also the Allocations instrument to identify orphaned (but not leaked) sets of objects which should have been released or just cases where your app is not responding to memory warnings as you expected.
https://developer.apple.com/library/ios/#documentation/developertools/conceptual/InstrumentsUserGuide/AboutTracing/AboutTracing.html might be a good place to start and there are a number of tutorials available as well; http://www.raywenderlich.com/2696/how-to-debug-memory-leaks-with-xcode-and-instruments-tutorial and http://www.friday.com/bbum/2010/10/17/when-is-a-leak-not-a-leak-using-heapshot-analysis-to-find-undesirable-memory-growth/ are among the first results I saw.
Vassily,
First, if you aren't yourself releasing extra memory, the the -didReceiveMemory warning does you no good and the OS will keep asking for memory until you are killed. This sounds like it is your problem.
Second, if that isn't the problem then you are probably getting terminated due to the size of your resident memory partitions. Make sure you look at your VM allocation in Instruments. I expect the MALLOC_TINY or MALLOC_SMALL both have greater than 5 MB resident and dirty footprints. Due to the nature of small allocations these VM regions will never shrink. The only option you really have is to not create a lot of small items in the first place. This is really only something you can address by changing you code's algorithms to use less memory.
Andrew

ipad application memory warning when using little memory

I am running an ipad application compiled for release and am seing memory warnings once in a while.
When I run the app on the device and connect Instruments, I see that the app never passes 40MB of real memory, but the warnings are still occurring.
What might be causing this? How can I better track down the reason?
40 MB of real memory is a lot, for an iPad. Even if it was not, the system will deliver the low-memory warning to you from time to time anyway, without your application being the main culprit. Tracking down precise memory usage in your application is sometimes hard, I’d suggest to spend some time with the Object Allocation instrument while working with the app. If you are not getting killed and you are sure that you do not leak the memory, you can also simply ignore the warnings.
40MB is high for the iPad considering it only has 256MB to start with. There could be other applications holding on to memory which will be killed off as more memory is needed. Just make sure you aren't leaking anything. Also use NSAutoReleasePools where applicable to reduce peak memory usage in memory intensive loops.

Resources