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!
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 would like to start testing my application on my iPhone. However, I have one concern.
What if my app has many memory leaks? If i ran such an app on the iPhone multiple times, wouldn't that result in a crash on my iPhone? i.e memory keeps getting allocated but never deallocated?
should i worry about accidentally creating unnecessary files on my iphone such that each time I run i somehow create a file that i dont delete, and it keeps taking up a few kb of space. I test the app many times and after a while i have no space left on my iphone. can such a thing happen? can testing on an actual device damage my phone???
Thanks!
What if my app has many memory leaks? If i ran such an app on the
iPhone multiple times, wouldn't that result in a crash on my iPhone?
i.e memory keeps getting allocated but never deallocated?
Memory leaks are only a problem as long as the memory is still allocated for your application. As soon as your application closes, or crashes, its memory is deallocated and returned to the OS. If you are running iOS 4 you can double click the home button and close the application to free up memory.
should i worry about accidentally creating unnecessary files on my
iphone such that each time I run i somehow create a file that i dont
delete, and it keeps taking up a few kb of space. I test the app many
times and after a while i have no space left on my iphone. can such a
thing happen?
Yea you should take care to create as few files as possible. However, because all files created by your app are contained in a little sandbox that is associated with your app they are deleted when your app is uninstalled. If you feel like your test app is taking up too much space simply uninstall it and then install it again using Xcode. Although I wouldn't worry too much about this as you would have to create A LOT of large test files before they started filling up your phone.
can testing on an actual device damage my phone???
I highly doubt its possible. That is one of the reasons that apple restricts which API's you can and can't use. If you jailbreak your phone and start doing things apple doesn't want you to do all bets are off.
I wouldn't worry too much about messing up your phone by developing on it. I've never heard of someone damaging their phone doing this and if for some reason you phone starts acting up just restore it in iTunes.
Here's a tip. Use Analyze tool in Xcode. Find leaks and remove them. And check the performance using Instruments. Fix your memory leaks using that as well. Once you do both diligently, there should be no reason to worry about leaks anymore. Your other concerns are a bit unnecessary. If you are using only the public cocoa touch APIs, your device should be perfectly safe :)
Also be sure to clean up any unused resources, etc. When you send it to the background, it only does so much. Make sure you release objects you own, and release the resources. Set autorelease when you can.
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.
I've had lots of problems getting a simple UIImagePicker working (see my other posts), and I've been getting memory warning notifications after taking a picture and before I even get a chance to dismiss the UIImagePicker
Now, however... I've loaded up my app in Xcode today and all is working fine. Can't get the memory warning at all, under the same build settings etc.
My question is.. is this normal? Perhaps it was cleared by an iPhone restart, or XCode restart. Or should I be worried that I've still got a hidden memory warning, only now it's hiding from me?
Thanks!
yes, very normal. memory is used by lots of background tasks on the phone, so it really depends what your email client is doing, whether you're installing apps in the background, and lots more.
It also depends a lot on the device you're testing on too. For example, if you're testing on an iPhone 2G, you'll have a significantly lower amount of memory to play with than if you were testing on a 3GS for example.
Depending on what kind of requirements your app has, and what choices you're making in terms of what to target (3.0 only? 3G upwards, etc) its best to always test on the least capable device so that you can get an accurate idea of how the app will perform on that device.
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