Codebeef Codebeef -5 years ago 131
iOS Question

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.




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?

Answer Source

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!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download