increasing memory allocation on iOS application - ios

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

Related

GMSMapView cached tiles are held in memory after zooming, leading to high memory usage and bad App performance

In my app i'm presenting a ViewController which displays a GMSMapView. Neither the ViewController nor the GMSMapView are supposed to be dismissed until the app is on the foreground, so the GMSMapView object is never deallocated, and since i'm also showing a GMSPanoramaView, with both being pretty expensive objects, i'm having a performance issue related to high memory usage.
After the app launch, when GMSMapView is initialized, the memory usage is relatively low and totally fine for my app requirements.
The problem comes after i zoom in, i'm experiencing a high memory increase which is never deallocated even after i zoom out. I'm not sure, but it looks to me like something is being cached by the SDK and never freed.
In the image down below (testing device: iPhone XR), you can see clearly the issue, where the first peak occurs while i'm zooming and from then on memory usage never decreases even after the zoom level goes back to 0:
I'm trying to decrease the memory usage related to the cache(?) but i have no idea on how to actually do it or even if it is possible.
From my understaing from the docs, the .clear() method only affects markers and overlays. I've also notice the stopRendering() method that could have been useful, it is deprecated tho.
On a side note, to do some general performance improvements related to GMSMapView, i'm already setting the MapView property .preferredFrameRate equal to .conservative to reduce the rendering frame rate, and also setting .isBuildingsEnabled = false and .isIndoorEnabled = false to avoid useless caching.
My question is: using GoogleMaps SDK, it is possible to prevent the up above mentioned caching or to free the memory once the map is zoomed out? If not, is there anything else i can do to reduce the high memory usage related to GMSMapView?
EDIT: this might come in handy for someone else, thus i'm adding some more GoogleMaps SDK optimization tips. I'm using a custom map style and i've found out, from my personal experience, that using Cloud-based Map Styling (currently in beta) is a bit faster in rendering map tiles than the classic .mapStyle = try GMSMapStyle(contentsOfFileURL: file) approach.
After a bit of research, i've found out that there is an open issue regarding the high memory usage: https://issuetracker.google.com/issues/35826246.
This was opened 6 years ago, not sure it will ever be solved, shame on Google.
Not much else to do, apart from starring the issue and hoping for a fix.

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.

This is Memory issue or not

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

Coreplot rendering Issue?

In my app, I am using Core-plot library to plot Vertical bar chart. When user taps on bar it should navigate to the another View-controller. (It will be off same view-controller's instance). When i push like this only for example 12-15 times i receiving memory warning & App crashes.
Did anyone faced same issue while using Core-plot library?
Thanks
Naveen.
Check your app by memory tools in Instruments.app. Maybe you can find some memory leaks. Memory warnings appears when your project use a lot of memory. And there is no reason to think that problem is in CorePlot. (as you said you creates more than 10 view controllers. Do you release them?)

Resources