Potential Memory Leak in iOS - 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

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.

What are the best ways to avoid Out of memory issues in iOS?

I am working on one application which has lots of screens, custom views and API calls on almost each screen. Sometimes when the user uses the app for a long time, it gets crashed because of Out of Memory issues.
Ideally, I followed all guidelines while developing app and ARC takes care of memory usage. So what are the best way to avoid such memory issues?
Code has a built-in memory profiler that can help you with this issue - for a tutorial on how to use it, this might be helpful http://www.raywenderlich.com/23037/how-to-use-instruments-in-xcode
Otherwise, if dealloc isn't being called it could be a symptom of a retain cycle (two objects maintain strong references to each other, so they are never deallocated).

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.

Amount of memory used by each thread

I am developing an app that is crashing due to an excess of memory usage. I would like to know the amount of memory that is being used by each active thread so that I can decide which allocated or drawn in screen elements release or remove from view. Is there a way to obtain it?
I have tried using mach.h library but with mach_task_self() I can only access the memory used by the whole application.
Thanks in advance
I think what you want is logMemUsage().
You can check the Answer from this Question :
Watching memory usage in iOS
I think you can get something from this Documentation also :
Understanding and Analyzing iOS Application Crash Reports
If you want to check Memory Usage While Application is Running then use Instruments. :
Using Instruments you can check how much memory your app is using. In Xcode4, use 'Profile' build, choose Leaks, then click the Library button in the toolbar and add the Memory Monitor instrument.
If you really don't want to use Instruments then you can use Custom Class UIDeviceAdditions :
Get current Memory usage
Hope it's Enough.
You can't because threads share the heap. Threads are created with a 512KB stack space, with memory pages allocated as needed. Other than that, there is no memory per thread value stored anywhere.

Core Text occasionally fails to produce results [iOS]

I’m helping out a company with a project for iOS, which is using Core Text. Some users of the app have reported that text is occasionally missing from within the app. It seems™ that this is somewhat memory related, because it’s solvable by shutting down the app along with background apps.
I made a few lines of code which simulates the use of the app – so the app “runs itself”, navigating between view controllers randomly, scrolling in text fields etc – to track if this issue occurs by normal use.
I’ve found some memory leaks related to the use of Core Text, but according to instruments the amount of memory lost is quite low. However, when the simulation has been running for about 20 minutes or so, the app is shut down by the os because of memory warnings.
I’m intending to fix this memory leaks, but my problem is that I will not be able to ensure that this fixes the main bug (missing text), since I cannot reproduce it myself.
So my final question is: have anyone experienced issues with missing text on iOS while using Core Text, which are due to leaked memory? Does it sound plausible? If so, is this related to only specific versions of iOS?
I appreciate any answers that can help me out!
UIViewControllers may implement didReceiveMemoryWarning that the system calls when your app is on low memory. Framework classes, as core text, are most likely do implement this and act accordingly to save memory. So it is possible that your core text object aims to help your app resolving the low-mem situation with freeing some of its resources that can even cause it to blank its contents. Fix first all memory leaks in your app.
On the other hand, all bugs are very difficult to correct if you can't reproduce them. If you suspect that the issue is due to low memory, try to simulate this yourself by allocating huge amount of memory in your application and hope that you can reproduce the erroneous behavior that way.

Resources