Memory leak detection at runtime in an iPhone app - ios

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

Related

Time profiler related error in Xcode profiler: Instruments

While profiling an app (which has metal codes for gpu acceleration) Time Profiler Instrument gives the error as in the screenshot:
It says, No configuration information received.
I want to know what kind of configuration is missing and how to configure it. I have also observed that other instruments: Allocations, Leaks, VM Tracker has no issues.
I would make sure OSX, XCode and the device's iOS are all fully up to date and power cycle everything. If that doesn't fix it, I'd temporarily modify the app's deployment target to the highest possible option.
If that doesn't fix it check to see if it happens using the metal demo (XCode->File->New->Project->iOS Game Metal) then look to file a bug with Apple: https://feedbackassistant.apple.com/

Difference in iOS allocation between XCode and instruments [duplicate]

I'm using XCode 7.0 with iOS 9.0 SDK & ARC, all profiling/testing done on an iPhone 5S with iOS 9. EDIT: for all screenshots, it was a single run: I ran a debug build straight from xcode, and then manually attached Instruments to it. So the screenshots are all from the exact same single test run. This memory growth (per xcode view) is 100% reproducible.
My app downloads ZIP files, unpacks them, and adds them to the camera roll. I've made sure to profile and catch memory leaks (ie. missing CGContextRelease) as well as using #autoreleasepool etc
During unzipping, in xcode I see the memory usage shooting up fast, never-ending until the unzipping finishes, and I cannot explain this because there are no objects in Instruments that I can see being held onto. The memory is never released (per xcode's memory view). At the end of my test run I see 236MB used, with no memory warnings during unzipping. If I use Instruments' allocation tool, I see 50.2MB of heap and anonymous VM used. That's a huge difference!
The first thing I did was assume that [UIImage imageNamed:was to blame (caching etc) because I have quite a few animated UIImageViews, so I spent time removing all imageNamed from my code, and using imageWithContentsOfFile instead. That didn't help at all. I add the unzipped images to the camera roll with iOS 8 Photo framework like this: [PHAssetChangeRequest creationRequestForAssetFromImageAtFileURL:[NSURL fileURLWithPath:filePath]]
I've spent considerable time pouring through Instruments and web articles but to no avail. Can anyone answer these questions?
Why the discrepancy between xcode memory usage & Instruments -- is this normal?
I assume that these numbers are too high for releasing such an app, and I have to improve this before I upload to app store, right?
Looking at the screenshots below can you make any suggestions where I could start looking for the problem(s)?
Thank you very much in advance for your help. Of course i'll post any source-code that would help, i'm just not sure where to begin...
XCODE MEMORY USAGE 236 MB
INSTRUMENTS
The most common cause of this is your configuration. By default when you run in Xcode, you build in Debug mode. When you profile in Instruments, by default, it builds Release. You can modify your Run and Profile configurations in your scheme to change this.

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

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.

Why the huge difference between XCode & instruments memory usage, and is it ok?

I'm using XCode 7.0 with iOS 9.0 SDK & ARC, all profiling/testing done on an iPhone 5S with iOS 9. EDIT: for all screenshots, it was a single run: I ran a debug build straight from xcode, and then manually attached Instruments to it. So the screenshots are all from the exact same single test run. This memory growth (per xcode view) is 100% reproducible.
My app downloads ZIP files, unpacks them, and adds them to the camera roll. I've made sure to profile and catch memory leaks (ie. missing CGContextRelease) as well as using #autoreleasepool etc
During unzipping, in xcode I see the memory usage shooting up fast, never-ending until the unzipping finishes, and I cannot explain this because there are no objects in Instruments that I can see being held onto. The memory is never released (per xcode's memory view). At the end of my test run I see 236MB used, with no memory warnings during unzipping. If I use Instruments' allocation tool, I see 50.2MB of heap and anonymous VM used. That's a huge difference!
The first thing I did was assume that [UIImage imageNamed:was to blame (caching etc) because I have quite a few animated UIImageViews, so I spent time removing all imageNamed from my code, and using imageWithContentsOfFile instead. That didn't help at all. I add the unzipped images to the camera roll with iOS 8 Photo framework like this: [PHAssetChangeRequest creationRequestForAssetFromImageAtFileURL:[NSURL fileURLWithPath:filePath]]
I've spent considerable time pouring through Instruments and web articles but to no avail. Can anyone answer these questions?
Why the discrepancy between xcode memory usage & Instruments -- is this normal?
I assume that these numbers are too high for releasing such an app, and I have to improve this before I upload to app store, right?
Looking at the screenshots below can you make any suggestions where I could start looking for the problem(s)?
Thank you very much in advance for your help. Of course i'll post any source-code that would help, i'm just not sure where to begin...
XCODE MEMORY USAGE 236 MB
INSTRUMENTS
The most common cause of this is your configuration. By default when you run in Xcode, you build in Debug mode. When you profile in Instruments, by default, it builds Release. You can modify your Run and Profile configurations in your scheme to change this.

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

Resources