CJPEGCreateImageDataWithData allocating a lot of unreleased memory - iphone

From using the Allocations instrument to track my app's memory usage I've noticed that throughout the runtime of the app the memory usage keeps going up. Looking through the heapshots I can see that the largest chunks of memory are being allocated by a method called CJPEGCreateImageDataWithData in the library GMM. I can't find anything online about this happening, but it certainly looks like this is responsible for my app's memory-hogging. Here's a screenshot of the pertinent part of the Allocations output:
What might be the reason for this, and how would I avoid it?

The simulator and the device use a different amount of memory due to several factors.
MKMapView should behave well enough on iOS 4.2 or higher. Even when you see a steep memory increase, note that it is cache memory, and all that is not required by MKMapView to work. The only problem is that it may bring your application closer to a low memory warning. You can emulate this warning and see if your app survives. Other than that, you can't control the map cache directly. If you don't have enough memory for your app to work, try using the normal map instead the satellite one.

Related

What's exactly behind / inside iPhone memory management?

This question is NOT about retain/release things in iphone memory management. I understand the routine quite well and there is no memory leak things in my app.
I pop up the question shown in the title, when I use Activity Instruments to monitor the overall memory activity of my app.
The instrument always shows that the amount of "real memory", which my app is using, keeps being between 21 MB and 30MB, never higher. I think this amount is relatively not big. However, sometimes, my app will give level 1 or 2 memory warning (never crash and I don't do anything for this warning in my code).
so I am wondering what's really behind iphone memory thing. I mean, does real memory the only things that triggers warnings? or there is anything else (such as virtual memory, as shown in the Instruments) inside the whole memory I should take care of?
Although my app never crash due to memory issues, this warning thing (especially level 2 warning) really annoys me and makes me fear of crashing once I release it to public in the future.
Any help?
Thanks
Memory warnings exist to tell your app you're nearing your limit. They are not necessarily a 'bad' thing - plenty of applications simply ignore them.
The actual implementation details about when a memory warning is triggered are not important, and in fact will vary considerably from device to device. An iPhone 4 might have 512MB of RAM to play with, but a 3GS will have half that.
That said, there are some things worth knowing about memory warnings:
A memory warning is triggered when the overall amount of available free memory reaches a certain level
These levels are undocumented. So you don't know what the difference is between a level 1 warning and a level 2 warning, other than the fact 2 is worse (more urgent) than 1
Memory warnings are not application specific. A memory warning is delivered to all applications currently running and not suspended. So you may not be directly responsible for triggering one.
When memory warnings are received the system will try and free up memory on your behalf
Again, the exact implementation details are undocumented, and you shouldn't need to care about them. A memory warning is an opportunity for you to help the system by freeing up any objects you don't need.

Why bother to use Memory warning event methods?

If my app uses less than 10MB do I have to bother to use those methods? I know that they are for caching low memory situations but this might occur only if you do not tested you app before releasing it. If you have tested your app, the app does not have leaks, have a small memory footprint, then why should anyone bother to use memory warning methods?
Your app is probably not the only thing running on the device. Other apps and processes are also taking up memory, and in some situations they may need it more than you. It's always a good idea to respond to memory warnings by releasing cached data that can easily be loaded again. That way the operating system has control over the memory usage, and it won't have to terminate your app.

What is the acceptable value for Live Bytes in Intsruments?

I was running my iphone app, optimizing to reduce memory footprint etc. I see that the live byte shows around 3.5 - 4 MB.
I was wondering what is an acceptable value. Put other way, what is the ceiling I should try to stay under.
Related thoughts, at what level do I get memory warnings, like level 1 level 2 memory warnings?
I am guessing this will have a direct correlation to my iphone device. Is there a matrix we can build depending on the device. I am using iphone 3G
thanks a ton
mb
if you stay under 20MB you should be fine, but as always the less you use the better ;-).
as far as I know the it isn't documented when the memory warnings are triggered, probably because that it is implementation detail and it can change at any moment.
Anyway you shouldn't focus too much on numbers (you don't know other memory consuming processes (safari caching pages, apps in the background using memory), just be a good ios-citizen, make sure you don't leak memory all over the place and your app will be working like a charm.

Object allocation and memory warning

i have an application which takes "live bytes" up to 3mb. The application showing memory warnings and it will crash continously. when i use object allocation tool i can see the live bytes.im using imageWithContentsOfFile in many places. i can see NSConcreteData object is taking more momory.what is the reson for that? may i know how much memory is allowed to an application.
You can't really know how much memory you're allowed to use, but in general you're fine up to 20mb on iPhone/iPod devices. However, your app can be killed not only for using too much memory, but for failing to decrease memory usage when warnings are issued. So even if you're not using all that much memory, if the system detects that you don't release any memory when getting memory warnings, your app might be shut down. At least that's my experience, maybe others have more detailed knowledge about what's going on.
imageWithContentsOfFile: has a built-in caching mechanism, so if you're loading the same images over and over, there should be very little overhead.
EDIT: imageWithContentsOfFile: does not cache images. The method imageNames: does cache images, and it's the only image creation method that does.

Do I trust ObjectAlloc or Leaks for analyzing my iPhone app?

When I run my iPhone app with "Leaks" (which has a section for Object Alloc), my app seems to be fine for memory allocation. However, when I run it with just the ObjectAlloc tool, the memory increases steadily as the app runs its main timer. (It is a timer based app). I'm not sure what to trust. I was just wondering if there are any issues with the ObjectAlloc tool that might pertain to me. Maybe something related to NSTImer? I'm running this on the device (not the simulator). Thanks.
Yes -- trust the tools. They are really quite accurate these days.
Leaks means an object or allocation for which the address of said object/allocation isn't stored anywhere else in your app. The memory is no longer accessible.
However, eliminating all leaks does not mean your app cannot grow without bound.
Unbounded growth can happen for a number of reasons. You might have a cache that keeps adding entries without pruning the least recently used entries. Or maybe a transaction log that is never truncated or flushed to the filesystem. Or you might keep loading new images into your application without throwing out the old.
Once you have eliminated all leaks, look at the output of ObjectAlloc and figure out where all that memory allocation is coming from. In particular, you'll want to figure out what your app is doing to trigger the allocations. The system frameworks won't spuriously cause continual growth without your application directly or indirectly asking for the resources to be consumed.