Reputation: 11231
I am developing an applciation whose run time memory goes upto 6-7MB. When I run the application it works fine but sometimes it breaks on device or shows white screen instead of actual views. When I did some testing I came to know that it was triggering the didRecieveMemoryWarning event.
Is it becoz of images, like I am using a lot of animation for which everytime I call the image animation function to get the array of the images. since I am using imageWithName, I need to call everytime. Also I am not supposed to release the memory used for the images as I dont own it. I think that this is not the right way to deal with it. Is there any good way to deal with this. do anyone have better idea or this is not the problem.
Please note that the code dont break on simulator wheras there is no breaking inbetween the code.
Upvotes: 1
Views: 1575
Reputation: 162712
The maximum amount of memory is going to vary, potentially significantly depending on a number of factors.
You shouldn't really target a set size of memory as much as just optimize every byte out of your code you can, starting with the largest inefficiencies and working backwards. You can use the ObjectAlloc tool in Instruments to gain insight into what is responsible for the largest number of allocations. It can also tell you the sequence of calls -- the stack -- that led to each allocation.
I'd suggest working through some of the CoreAnimation examples for more information, barring someone piping up with a useful, concrete, example here.
Upvotes: 1
Reputation: 4924
If you know that the memory usage is coming from images that you can discard, then you can use [[UIImage alloc] initWithContentsOfFile: ...] and cache and discard as you see fit.
However, it sounds like you're not positive that's the issue. I highly recommend getting comfortable with some of the profiling tools Apple provides, such as Leaks and Object Allocations. This might point you to some large object allocations that you can discard.
Upvotes: 0