What could be causing the memory leak in my iOS project? I failed to locate any dubious custom methods using Instruments - ios

According to this answer, locating the method causing memory leak is pretty simple with the help of Instruments.
But in my situation, the "extended detail" column doesn't show any of my custom methods, as shown below:
How should I locate the leak point now?
Thanks,
snakeninny

The key is to launch Instruments via Xcode -> Product -> Profile. And then choose Leaks manually, you'll be able to see all the leaking symbols now.

Related

Xcode memory tools disagree on presence of Zombie Objects

My app seems to have a memory problem. I'm not getting any crashing, but when testing on device, both Instruments and the Debug Navigator agree that the amount of memory my app is using keeps increasing depending on what I'm doing in the app.
So, I tried to diagnose the problem.
First, I thought about normal memory leaks -- and there were many. So, after a lot of work with the Instruments -> Leaks template, I was able to eliminate them.
But the memory problem persisted.
So, I decided to look for zombie objects. First, I enabled zombies in Xcode. Because I was unsure whether I needed to enable zombies for "Run" or "Test" or both, I did both. So, that's Edit Scheme -> Run -> Diagnostics -> Zombie Objects and Edit Scheme -> Test -> Diagnostics -> Zombie Objects.
I was also unsure whether to run Instruments through a debug or release build configuration, so I tried it with both (with the same outcome).
Here's a screenshot showing the location of the Debug Navigator:
Here's a screenshot of the memory options I enabled prior to using View Memory Graph Hierarchy:
Now that zombies are enabled, I go to Debug Navigator -> View Memory Graph Hierarchy, and Xcode builds a memory graph that says my app has something like a thousand zombie objects. There are zombies of all kinds -- everything from SceneKit stuff to CloudKit and GameplayKit stuff.
Here's a screenshot of some of those zombie objects:
So, I decided to investigate further using Instruments.
Here's what Apple says on using Instruments to detect zombies:
"If a call is made to a deallocated object, a flag is inserted in the
timeline pane and a Zombie Messaged dialog appears, indicating that a
message was sent to a deallocated object at a specific memory
address."
However, if I open Instruments and use the Zombies template, I never see any such flags/dialogs.
Here's a screenshot showing what I see after running the Instruments Zombies template (notice the lack of flags/dialogs):
Question: Why might the memory graph hierarchy tool and Instruments disagree so markedly on the presence of zombies? Is there some further Xcode configuration I'm missing or something? How should I proceed?
Thanks!

Is it possible to debug "Terminated due to memory error"?

In a certain (consistent) point when my app is running, I consistently get the xcode error message
Terminated due to memory error.
I cannot find the code causing the error, but I can tell what code is near the error (using breakpoints).
The error is caused directly after returning a certain cell in my implemenation of the
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
UITableViewDataSource delegate method. I can confirm that it is returning a valid UITableViewCell, but I think that explaining and posting that entire method would be a waste of your time. However, I suspect it might be caused by a rapid, massive allocation of memory.
It definitely says Terminated due to memory error, not memory pressure.
I would like to know what is message really means. Also, is there any way to debug this message? No crash report is generated.
I am using ARC and iOS 7.
I was getting this error and could not understand what was wrong.
After some searching I found out that i forgot to disable zombies.
To disable do the following:
I was faced the same issue.("Terminated due to Memory Error")
I had tried the above all answers but nothing work for me. Then i debug my code and found a for loop is running for infinity time with allocating memory to a array with nil value every time.its use 300+MB so it give this error
Thanks.
I had exactly same issue. I thought it caused my program had memory leak or using too much memory. I use instruments and used allocating profile and program works fine. Also I ran program by device long enough, and it also works fine.
I also using iPad 3rd Gen for debugging, it might be causing because of that slow of the device or bug, it it seems like just Xcode and running from Xcode problem. Not the problem of memory leak or allocation.
If you make sure with instruments and running app on device itself and work
I was using Tesseract for OCR and when my target text got scanned, a GIF was supposed to play. When the GIF started to play, there was a memory spike, from 70-80MB to 450MB. The problem was that GIF was taking too much memory, the app would crash and Xcode would show that message. So I removed the concerned imageView from the superview of the ViewController.
imageView.removeFromSuperview
After this, the app would still spike to 450MB but then immediately release and come down to 40MB
Restart device worked for me. “Terminated due to memory error” message stopped to appear.
Edit the scheme, under Diagnostics you'll find several options to guard allocations. Refer to the documentation for details.
Question is: does it really say "terminated due to memory error" and not "pressure"? Check in instruments if your app is running low on memory, if the app does seem to run low on memory then that's what you should focus on regardless what the exact message is.
I got this error because I was adding full size photos to a collectionView cell sized 40x40. Read the 2 comments under the question from #matt. I had to scale down the images before adding them to the cell.
I had similar issue in Xcode 11.3 wherein camera was getting calling every-time we press on try again button. If these is done multiple times then crash happens.
This was fixed when we disabled Zombie objects. Below are steps:
Tap on project name present in top left. This will show list of targets present in project.
Tap on Edit scheme
Select Run option -> Diagnostics -> Uncheck Zombie Objects.
Now, run your project. It should work fine.
With Xcode 11 it started my project in Debug mode. I am doing some image recording/editing/returning to the user and that is not something you can use in Debug. Once I turned to Release mode, all went well.
I've faced this kind of issue due to inattentiveness.
I've been calling a function, which adds imageView as subview in:
override func layoutSubviews() {
super.layoutSubviews()
}
This caused a huge memory usage, so be attentive to this sort of things!
The thing that I noticed is that when I run my app on the device through cable and leave it idle for a long time I will also get that error.
Apple do address this and it just might be that it feels like the app is idle and just kills it.
In my case it was a corrupted Image from the API which raised my memory from 100MB to 4.5 GB due to processing size it took to display on screen!
An infinite loop was the cause of the memory leak for me. I could see the memory in Xcode rising to 1,6 Gb at which point the app crashed. The app's memory usage should be in mb and not gb and it should be relativly stable. If it rises quickly, say 100 mb a second, there's definitely something wrong. If none of the suggestions above have worked, you should 1. check the memory usage of the app, and 2. if the usage is too high, look for loops you've recently added.

Running leaks on iOS app throws "Cannot allocate mmap" error

I have created an iOS app and need to check the leaks in the app programmatically.
(Hence not using instruments directly)
For the above I use the leaks command as follows:
MallocStackLogging=1 leaks -nocontext
At one point of time this was working properly without issues. But recently I have started getting errors and the leaks commands gives different number of leaks each time.
Has anyone faced a similar issue?
You can programmatically find the current memory stats using vm_statics object. Go through these links to find an implementation of vm_statistics:
1)
http://gamesfromwithin.com/whered-that-memory-go
2)
http://landonf.bikemonkey.org/code/iphone/Determining_Available_Memory.20081203.html

Memory leak detection at runtime in an iPhone app

Is there a way to programmatically find out the memory leak at runtime in an iPhone application?
Perhaps not programatically.. But there is the Leaks tool that comes bundled with Instruments and XCode.
You can programmatically find the current memory stats using vm_statics object. Go through these links to find an implementation of vm_statistics:
1)http://gamesfromwithin.com/whered-that-memory-go
2)http://landonf.bikemonkey.org/code/iphone/Determining_Available_Memory.20081203.html

Leak in Icarousel memory leak

https://github.com/nicklockwood/iCarousel/downloads
There is a memory leak for iCarousel how to resolve the issue.
I am using this in my application. so i need to resolve the memory issue [leak's] while using the iCarousel.
As per my experience before leak testing make sure “call tree” options is selected as well as for better result set Sampling option to 5.0 sec.
Actually in the testing we mostly concentrate open only those leaks which
Is generated within our code. So that’s why select “Show Obj-C Only” option from Call tree.
Follow these steps:
➢ Activate call tree block.(Choose Call Tree option from drop down menu on the clicking on Leaked Blocks option)
➢ Choose “Hide Missing Symbols” , “Hide System Libraries” and “Show Obj-C Only” option.
You can use many programs for debugging. for example, try Deleaker.
I think you should start with the plugin developers:
Pull a request there : https://github.com/nicklockwood/iCarousel/pulls
See :
You have better chances over there to find about your issue and i believe they will be interested with your case if iCarousel in involved .. if there is a case.

Resources