I'm doing some performance testing in Instruments on the device for an iPhone application that is in development.
I'm seeing that the two largest chunks of memory that are been allocated aren't through any of my custom methods (to my knowledge).
Screenshot 1: http://i.stack.imgur.com/yFFux.png
The background to the application is that it is an application, which uses CoreData to consume a web service and store/display the data. Linked images are then downloaded (async), resized to a smaller size within the app and the new image is then displayed. I originally thought that the images were the problem but testing the app in offline mode without the data or images been downloaded and the large Malloc of 4.5mb still appears.
I'm struggling to identify the source of the memory footprint and ultimately try to reduce/remove it through an AutoRelease pool or another means.
It's really hard to diagnose memory issues from a few screenshots. Your best bet is to learn a bit more about instruments and memory profiling so you can determine for yourself what the problem is. I highly recommend watching the WWDC 2010 session 310 - Advanced Memory Analysis with Instruments. It really helped me to learn where the problems in my app were.
Related
I am working on a mail client on iPad (similar to that of the default app client) and using core data framework as a cache to increase performance . My app uses around 4.5 - 5 MB of heap memory and then it crashes because of memory overflow (detected this using allocation instrument). If I try to reduce memory my performance becomes very slow and sluggish because I am not able to cache my views, data structure (which store folders and all the mails) and tableviews.
I have checked my crashLogs and I see jettisoned written in front of my App which confirms that OS has forcefully closed my App!
I have used instrument to detect these limits. Please find the attached image here
This is a snapshot my recordings just before the app crashes.
I have tested my app on simulator and it stabilizes itself at 6 - 7 MB of heap memory.
Is there any way so that I can ask OS for more memory or avoid crash with a little redesign in my code.
Any suggestions or help would be highly appreciated.
6-8MB of memory should never be a problem. Likely you are either trashing memory or if you are running a debug version and have Zombies turned on, the default is to never delete the zombies. NSZombiesEnabled=YES and NSDeallocateZombies=NO will appear to leak memory as nothing is ever deleted.
I am currently working on a personal iPhone project that is very audio and graphic-intense and I have therefore been quite conscious of how much of a footprint my application has (in terms of both memory usage while active and/or in 'multi-tasking mode' and how much the size of application is) as Apple sub-consciously gets into my mind and has drilled in the fact the iPhone has limited memory and capacity - and I was curious if any of you guys had any solutions that could help me keep down the usage of my application - I've open up Instruments and configured some aspects although this primarily appeals to me as a performance utility). I have also been testing on my device as I cannot stand the simulator...
As long as you are properly releasing objects that aren't being used, you should be fine. If you are loading large images and audio files, then your app will require more memory to handle those, so alloc/release those as they are needed.
Also, debugging memory issues on the Simulator just wont work, so don't rely on it for testing memory issues.
I'm having frequent crashes on iOS 4.0 within my application due to excessive memory. Instruments tells me that it's category is "Malloc 600KB" and the responsible library is ImageIO and the responsible caller is ImageIO_Malloc. I'm using lots of images in this app but no more than I have used in other applications. It's odd because if I run the same code on 3.0 then I have no real problems and on 4.0 sometimes it will jump from 5MB to 30MB Memory even if I haven't touched it and it hasn't loaded any new images (as far as my knowledge goes).
Does anyone have any ideas or know how I might find the source of the problem?
Thanks in advance!
I ported one of my mac applications to the iphone. WOW!!! is it slow! At first I started thinking maybe I was doing a lot of disk access. But as I started looking I realized I simply do an offset read of a binary file. I only read in about 512 bytes of data. I also have an array that is huge. Maybe 2MB. But why would that be slow? It is perminatly located in memory.
I would love to hear some ideas from you all!
When you have major performance problems, the tool to pull out first is Instruments. Start with "Run With Performance Tool > CPU Sampler" and get a feel for where your app is spending its time. After that, check Object Allocations to see if you're hitting memory harder than you should. iPhone is a resource-constrained environment compared to the Mac. Things that you think of as fast can dramatically impact performance on iPhone. Disk access is much more expensive. Even allocating memory can be a significant impact (welcome to the world that server developers deal with every day). You only have one core, so things you stuck off on a background thread now compete with your main thread. It's a different world.
It's hard to debug the application over Stackoverflow, but there are many reasons why the iPhone app runs much slower: Your mac applications run on probably the latest CPUs with tons of memory, as for the iPhone it's very limited (3GS is rumored to have 600MHz CPU with 256MB RAM). Also, Mac applications are a bit more forgiving when it comes to memory usage; as for the iPhone it's important that only create the objects you need when you need them and release them when you no longer use them. Delaying object de-allocation results in some slowdown as well.
I recommend using Instruments performance profiling tool, that is bundled with XCode and the Developer tools. It'll give good tips on what the bottlenecks are.
I have 3 memory leaks after the launch of the iPhone application. These remain constant no matter what I do in the App (no more leaks).
My Net Object Allocation keeps growing. There are two blocks in particular, GeneralBlock-24 & GeneralBlock-48.
Block-48 gets specially bad as the program is being used, taking Megabytes of memory. The Library that seems to be allocating the objects in both blocks is QuartzCore.
The App had a reference to the QuartzCore framework, but I have eliminated all references to it.
p.s.: this is all on device, not the simulator
Found it! When running it on the simulator with Instruments the GeneralBlocks are reported as a single GeneralBlock-0. Searching through the web it seems that there is a bug in instruments objectAlloc reporting and QuartzCore.
So I just added a Memory Monitor instrument and saw that even though my Object Allocation kept growing non-stop, my Real Memory remained flat (well, moving up/down within half a MB)
I hope it's useful info to others, I spent a day searching for GeneralBlock-24 & 48 trying to figure it out until deciding to run it in the simulator just for the heck of it