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

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?

Related

Potential Memory Leak in iOS

So I just made an app that loads a map with some markers on it. The app has a navigation controller that segue from the main screen to the map and back. While running the app on my phone and simulator i noticed that if i went back and forth between the home screen and the map, the amount of memory that the app was using just kept growing indefinitely. Is there way to assist in the process of memory management (i know the system uses ARC)? Im using the google maps sdk btw.
Thanks!
Does it cause the app to run out of memory and crash?
Or is it using a ton of memory, receiving a memory warning, and dumping said memory?
So, unless it is causing crashes, it may be behaving correctly.
Apple has extensive and well-documented support for diagnosing these kinds of problems. See "Locating Memory Issues in Your App".
Check your codes where using NSThreads and GCD blocks. If there are some places you create plenty of threads, it is recommended to add a autoreleasepool block.
Memory may leak in these situation:
If you are writing a program that is not based on a UI framework, such as a command-line tool.
If you write a loop that creates many temporary objects.
If you spawn a secondary thread.
For reference: Using Autorelease Pool Blocks

How to track the code responsible for Heap growth in iOS

I have spent few days working on this issue. That my app is getting crashed in iPod Touch due to Memory leak.
I have monitored heap growth exactly by Instrument in Xcode and it is confirmed that code is making memory occupied by app grow on each event.
I need to mention here that I am using ARC and hence i was really not expecting app to crash because of memory issue, although ARC isn't helpful incase Core foundation is used but I haven't used Core foundation in my app directly.
But MBProgressHUD is added in my app which uses this framework. I have not enabled ARC for MBProgressHUD as it was causing lot of memory grow.
I still am unable to track the main problem/variable/code which is causing my app memory to grow so much and causing app to crash.
P.S : Instrument had shown few functions causing lot of memory allocation but in those functions also I don't know how to free those variables as ARC is enabled (It is managed automatically).
Please suggest if I am in right direction.
Is it leaking or allocation is more? main cause for the app slow down is using too many number of autorelease objects.

How to access current memory warning level in DidReceiveMemoryWarning in Monotouch 6.2 (Xamarin.iOS)?

I would like to know how one can programmatically access the current memory warning level in DidReceiveMemoryWarning, in Monotouch 6.2 (now called Xamarin.iOS), working with iOS6.
Also, how many memory warning levels are there?
The reason for this is that I would like to see the severity of the warning and accordingly do the needful in releasing memory resources.
If there is a way to get this using Objective C, I can probably work out the equivalent way in Monotouch. I did not find anything about this in the Monotouch documentation.
Thanks.
There may be only one warning, or an infinite amount.
If you get a warning and don't free anything, your app will most likely be killed before you get another one. If you do free memory, and later use it again, you might get another warning, and this may go on indefinitely.
When you get a memory warning you should just free as much memory as you can, there is no way to know how much iOS actually needs, so just err on the side of caution and clean up as much as you can.

Will iOS app's memory leak leverage any vulnerability?

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. :)

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.

Resources