Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

  1. Why the discrepancy between xcode memory usage & Instruments -- is this normal?
  2. 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?
  3. 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 xcode mem usage

INSTRUMENTS instruments vm summary

instruments allocation summary

like image 474
xaphod Avatar asked Sep 28 '15 12:09

xaphod


People also ask

What is difference between Swift and Xcode?

Swift is a programming language that is used for building iOS and Mac applications, while Xcode is not a programming language – it is a comprehensive IDE. Xcode is the canvas to write and program the code, while Swift is the actual code that your team is writing.

Which is better Swift or Xcode?

According to the StackShare community, Xcode has a broader approval, being mentioned in 1052 company stacks & 604 developers stacks; compared to Swift, which is listed in 994 company stacks and 541 developer stacks.

Is Xcode better than Visual Studio code?

If you want an IOS app you must use Xcode. You can't make an app for android using Xcode or using Android Studio you can't write an app for IOS. But you can make an universal app using Visual Studio "Cordoba". Visual Studio best documented one and more community support you can find for.

What is the alternative of Xcode?

Google's Android Studio is one of the best cross-platform IDEs that can serve as a free alternative to Xcode. The tool works seamlessly on the Windows, Linux and macOS operating systems. Several programming languages, such as Java, C++, Go, etc., are supported by this platform.


1 Answers

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.

like image 180
Rob Napier Avatar answered Oct 17 '22 07:10

Rob Napier