iphone iOS memoryWarning handle for navigationController and ALAssetlibrary - iphone

I do resizing for FullReoslutionImage, so it may introduce memorywarning from iOS.
When I recieved memorywarning, it sometimes unload my ALassetlibrary for album, and it introduce crash when users choose image.
How could I prevent this kind of problem, how to unload my other resources and other viewController?
On other hand, when viewcontroller is unloaded, when I go back to this view , it seems introduce crash. How to prevent it ?
Thank you very much!!

I found it was reduced much when I use 3rd party JPEG decode library to decode&resize it under 2048x2048 UIImage. So the memory wanring happen so often may be caused by creating UIImage larger than 2Kx2K.
Hope this helps.

Related

deleting image heavy custom uitableviewcells

I have a table which is made from custom UITableViewCells which contains downloaded images.
Ive found the app crashes after too many images are displayed. How can best stop this? I don't mind deleting the first images, but don't know of the best way to do it.
EDIT
How do I write the images to the device for caching?
Post your cellForRowAtIndexPath code. Sounds like you have a problem there. If you're certain you do not, then when you receive the memory warning, release any objects you do not need, and can easily be loaded again if required. These objects may be in other ViewControllers not on screen or ImageView objects already displayed.
Best we can do unless you post code.
Or read Apple's Memory Management Guide.

How to control the crashing of my app when i switch between tabs

I have created a music application in iphone .
The App crashes if i keep on switching between the tabs while the song is playing.
How can i solve this problem .Please anybody help me regarding this problem
Generally such kind of issues are memory related.......just check whether ur releasing the objects at proper place or not..
Other u can put some code snippet to have a look so that we can know actually what's happening with your code..
A common cause for crashes when something repetitive happens (eg switching between tabs, screens etc) is memory problems. Make sure you are releasing the correct objects in the right place. It could very well be that every switch you are allocating objects - without freeing them when switching again. This will eventually consume your memory and crash the application.

Seeing malloc allocating large chunks of memory - trying to track down why (iPhone)

I'm seeing my app being killed by iOS with an out of memory message, however, while tracing the progress of the app in the Allocations Instrument, I see lots of mallocs that seem to be occurring outside of the code I've written.
I'm not seeing any leaks being caught, so I assume these allocations are supposed to be there. Thing is, because I'm not sure about why they have been allocated, I'm not sure what I can do to optimize the app and prevent the OS from jettisoning my app.
Does anyone know why the memory is being allocated, or is there any way for me to find out?
Here are a couple of shots from Instruments showing the mallocs. In the second shot, all of the allocations have the same stack trace.
EDIT
I' displaying a single large image as the UIView background (1024x768), then overlaying a smaller (600px square) UIView with some custom drawing and a third UIView (550px square) over the top of those that contains two 550px square images overlayed.
I'm guessing that this is not appropriate, and there is probably a better way of achieving the composition of views I need for the app to work.
Should this be possible on the iPad?
I think there's not really much information to go on here - if you add a bit more information about what this view in your app is doing you might get some more informed suggestions.
From the screenshot, it would appears large blocks are being allocated to display an image.
Given that I'd hazard a guess that either you're trying to display some very large images, or you UIView is large, or you have more UIViews in memory that you need to display the current screen.
I guess the easiest way to track down exactly where they're coming from would be to disable the part of the application you suspect then run again and see if the allocations still occur.
EDIT
Are all the images the same size as you're displaying them? (ie. are you trying to display a 5M photo as the 1024x768 background?) If not you probably need to scale them down to the size you are display them, or at least closer.
If you're not needing transparency, make sure to make all the views opaque.
I figured out the source of the problem - I was using
[UIImage imageNamed:#'Someimage']
to load in my images. This, as I'm sure many people are aware, caches the image data. I had enough images of sufficient size to cause my app to be jettisoned.
The problem was apparent not because of the size of the image but because of both the size and number of images I was using. The lesson here is be careful with [UIImage imageNamed:].
Thanks for all of the help, chaps!
Mallocs can occur inside of other API's that your app calls (such as loading images, views, playing long sounds, etc.) You can try changing the size of your images, views, sounds and other objects by various amounts as a test, and see if the size of the malloc'd memory changes track one of the changes that you've made.

UIImagePickerController returned image woes

I have a UIImagePickerController that lets the user pick an image from their library, edit it, and then save the product out to disk. Before it saves, however, I need to update a UIImageView to hold the edited photo. But when I go to set the UIImageView's image property, the program crashes. It still can save to disk.
The UIImageView is an IBOutlet and the dimensions are 88x88, if anybody cares.
I can reproduce this issue on a device (iPhone 3GS running iOS4) and in the simulator (iOS 4).
Don't you know what the error is? Especially in iOS4 you should see an entire stack trace in your log.
Most likely culprit would be a bad Interface Builder link... from there you should do retain count on your actual UIImage to see where it is when you assign it to the ImageView...
Anything after that, I suspect, would be application specific.

How does UIImage work in low-memory situations?

According to the UIImage documentation:
In low-memory situations, image data may be purged from a UIImage object to free up memory on the system.
Does anyone know how this works? It appears that this process is completely transparent and will occur in the background with no input from me, but I can't find any definitive documentation one way or the other.
Second, will this data-purge occur when the image is not loaded by me? (I'm getting the image from UIImagePicker).
Here's the situation: I'm taking a picture with the UIImagePickerController and and immediately taking that image and sending it to a new UIViewController for display. Sending the raw image to the new controller crashes my app with memory warnings about 30% of the time. Resizing the image takes a few moments, time that I'd rather not spend if there's a 3rd option available to me.
I think this is the answer. In the documentation for initWithContentsOfFile: it says:
This method loads the image data into memory and marks it as purgeable. If the data is purged and needs to be reloaded, the image object loads that data again from the specified path.
None of the other methods in UIImage mention purging, so it appears that initializing a new image from a file is the only way to get this low memory behavior.
In answer to your second question: Save it to a file, and then use:
[NSData dataWithContentsOfMappedFile:]
to do the resizing. Using a files as intermediates, is rather slow though.