This is Memory issue or not - ios

When will i have running my app in simulator. xCode debug section shows cpu and memory section it will display some graph flow. but i don't know what is that.
My question is,
what is that cpu and memory graph
when i running my app the memory increase towards when ever i navigate to any other viewcontroller and return back same or other viewcontroller etc., it always increase the memory size.
why it occurs. Is that any problem. if yes how to fix that and why i caused.
Here below image i navigated to any other view controller. it is suddenly increase from above image memory size to below image memory size.

Well from overall memory consumption it would seem as if you are handling some images or videos or other heavy content. Many make memory leaks handling those. To test if thats a real leak, you can do so:
Go to some page A (any page), from there go to some other page B, then back to A, back to B.. repeat that and if your memory is really getting high - you have a leak.
BUT bear in mind: These graphs show you how much resources your app use from your device, you SHOULD NOT use that to find leaks. Instead go to profiler, choose memory leaks and use that. If you are using ARC and cannot find any leaks, you can use "mark heap" button in allocations instrument to find memory build ups like this: Repeat the "page A page B" cycle and every time you are in page A, press "mark heap" button. You will now see generations which each show how much memory has increased from last generation. If it always keeps increasing same amount - double clicking generation will show you all the places that you have possible leaks.
Additional info: Easiest way to profile your app is to hold left mouse on "play" button in xcode until more buttons pop-up. Choose profile. When instruments appear - choose "Leaks".
From there - you should be able to see overall statistics of your app. I will not go in detail about profiler, because all the info is already available in the net. For example: https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/Introduction/Introduction.html

Related

Out of Memory issue iOS

In my iOS app I am running the instruments tool to see the memory allocated. In the app I call CoreData and use that to create a survey using Apple's ResearchKit. Every time I run a new one I see an increase in the amount of 'persistant bytes' increases. When the app is run, whenever it is run multiple time over and over eventually the app closes.
I can see using Fabric's Crashylitics that a Out of Memory session occurred.
What's the best way to go about finding and fixing the memory that seems to be retained?
Your screenshot is not showing any memory leaks so you should start by using the Allocations instrument, the graph of which is in your screenshot.
Start by setting an inspection range where the memory usage spikes. Click in the graph and drag to set the inspection range. You will notice that the graph color outside the inspection range changes to gray. At this point you have focus on where the memory usage spikes.
To find the place in your code that's causing the increase in memory usage, switch to the call tree view by clicking in the jump bar below the graph and choosing Call Trees. Inverting the call tree and hiding system libraries makes it much easier to find your code in the call tree. Click the Call Tree button at the bottom of the window to invert the call tree and hide system libraries.
If you find a function in the call tree that is allocating a lot of memory, you can double-click it to show the lines of code that are allocating the memory.
Another tool you can use to analyze memory growth is the Allocations instrument's generations. Run your app, pause, and click the Mark Generation button to create a generation. Repeat to create multiple generations. Choose Generations from the jump bar to see how much memory growth you have from generation to generation.

iOS - Terminated due to memory issue

I'm having a memory issue with one specific ViewController and memory. When I launch my app in debug mode, it launches with 40mb memory usage. (I have no idea if this is already a lot or not -- what is common?). Then, when I open this specific view, it spikes up to about 120mb. The issue is, when I pop this view (with the navigationController popViewController), the memory stays up at 120mb. And then, when I re-open it, it spikes to 200mb (a 80mb increase every time).
With other similar ViewController it spikes up to 120mb too, but when I close the view, it goes back down to more or less 40mb.
The problem is that this specific view contains quite a bit of code (about 1000 lines...) and it's impossible for me to post everything here.
What methods should I use to specifically locate the issue in xCode?
For anyone I might be able to help with this:
use the tools in xCode as recommended. There are some great tutorials online.
In my case it was an issue with an [NSTimer] which kept a strong reference to my view, so it never got released afterwards, thus stacking up memory. Make sure to stop your time when you pop a view.

Memory result from Xcode is different to Instrument

I am trying to see how much memory my program uses and identify leaks. I have tried looking at the memory page built into xcode and also the Allocation instrument. They get totally different result though (Both simulated on my 6s).
An outline of what I did...
I have a tableview that loads images from firebase. My test was keep pressing "reload all data" button at 3 second interval for a bit (30 seconds) and observe how the memory reflects what I did. Below are the results of the two screen shots.
What is weird is that for xcode result, I see that my memory just continues to climb higher and higher upon every refresh (Which suggests that I have a leak somewhere as the table view should discard the original data and load new ones. So I would expect highs and lows). So I went into the allocation instrument and did the same test. However, what I instead see is that the total persistent byte doesnt grow as crazy as before and remains hovering around 23.36mb with minor highs and lows (As what I might expect for reloading a table?)
Any explanations?
-- Update--
The answer here appears to contradict to what I believe is right
Xcode Memory Graph - showing increasing memory use - what exactly does it show?
Because I have tried hitting the refresh button for an hour to let the memory build up to nearly 1.5GB and I did get a memory warning. So I dont believe Xcode is showing "total bytes".

increasing memory allocation on iOS application

I've developed an iOS application. There is a main screen which is displaying a google map and there are many markers, polygons etc in it.
At the beginning app was using around 120MB of memory.
- I touched settings button of my app and went to the settings page. there is no code. only segue connection in the storyboard (red line on the image)
- then I came back to the map screen (white line on the image)
You can see the memory allocation. every time when I open the map screen memory usage is increasing
What is the problem. What should I do?
The graph you have captured in Xcode is a decent overview of your memory consumption, but I'm afraid you are going to have to use more specific tools to diagnose this leak: Instruments comes shipped with Xcode and will help you track memory leaks; you will have to research (at least) the Leaks and Allocations instruments to figure out why your View Controller isn't being released.
While it is impossible to diagnose without seeing your code, that graph heavily suggests that your map view controller is not being released (hence the steady growth each time you create a new one)
To hazard a guess, I'd imagine you are creating a new mapView in viewDidAppear rather than viewDidLoad

iOS questions about Instruments tool, memory issue in my app

I just started learning the instruments tool, and I'm pretty sure what I am seeing is not good. When I look at allocations, specifically the column "Live Bytes" and "Overall Bytes", I see the number continually increases as the app runs...
My app has two view controllers. A table view, and the second view controller displays detailed information about the row they selected in the table view, downloaded from the internet.
I kept clicking a row in the table view, followed by clicking the back button in the navigation bar... and LiveBytes continued to increase.
I'm guessing this means that my objects aren't being released from memory... but please correct me if I'm wrong.
MY QUESTION IS: How do I use the data in instruments/allocations to track down this memory issue? How do I find the objects not being released from memory?
I'm looking for tips on how to use these tools to clean up any memory problems my app has.
Thanks!
XCODE 4.2.1, deploying to iOS 5.0+
EDIT: I'm looking at the #living column and seeing objects like UIScrollView continuously increase... and never decrease. When I click the back button in a navigation bar, are objects automatically released from memory? When are objects released, or do I need to do it manually? Or could I be running into an issue due to using strong pointers, causing objects to not be released?
Whenever you want to observe memory usage in a cyclic pattern, there's the wonderful Heapshot analysis in the "Allocations" instrument.
Start your app and go to a default state.
In Instruments, press the "Mark Heap" button to create the "Baseline".
Do something in your app like pushing a view controller.
Return to the default state.
Press the "Mark Heap" button again to create a heapshot.
Repeat about five times from step 3.
This will result in a list of heapshots, each showing the objects that are still alive from that cycle. If your app has no leaks there will be no objects left in the middle heapshots.
The first one or two cycles might have warmed up some caches, the last two might not have cleaned up some reused resources. That's why it's usually a good idea to make four to six heapshots.
The magic in the heapshot analysis lies in the fact that the heapshots show you the leaked objects from previous cycles and remove them automatically when the objects are released later. In contrary to the "Leaks" instrument it also finds abandoned memory, not only leaks.
Most Probably you have discarded the arm64 and are running your app with armv7 only. Add both arm64 and armv7 as architectures
I think one of the best ways to solve memory issues is to use ARC.
Edit -> Refactor -> Upgrade to Objective-C ARC.
ARC will handle the majority of memory management in your app. Especially sice your app doesn't sound too complex, it might totally eliminate your problem. You still need to watch out for retain cycles and listen to memory warnings though. If you don't want to use ARC (which you should) at least run the static analyzer. Your problem might be something simple that the static analyzer can show you how to fix.
Edit:
You mentioned scroll views- this might be your problem: Memory leak every time UIScrollView is released
The profile tool has an instrument called 'Leaks'. It is similar to the 'Allocations' instrument but it shows you the object that was not released. May be you can use the 'Leaks' tool to find what is the object that was retained and release these object.

Resources