-->

(iphone) my app gets memory warning when instrumen

2020-07-27 04:24发布

问题:

as question says, it dies at 7mb..

Is this normal? ( 7mb..)
instruments shows no leaks.

Thank you

  • EDIT

edited 17mb -> 7mb. I lowered memory usage by taking out unnecessary pool I was allocating.

Still, it gets memory warning at 7 mb.. I'm essentially creating images and releasing them constantly when it gets the warning.

I'm doing a lot of

- (UIImage*) allocImage
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    UIImage* uiImage = [UIImage imageWithData: imageData];
    UIImage* changedImage = [uiImage changeColor: self.currentColor];
    uiImage = changedImage;
    [uiImage retain];
    [pool release];

    return uiImage;
}

and releasing the uiImage I got (instruments shows memory goes up by 2-3 mb and goes back to 7mb)

Each image is 1mb big on memory, and I should probably have create/destroyed image about 100 times by the time the app gets the warning.

  • Edit 2

found similar case, no solution there though..

My iphone app gets memory warning and killed at 6.8MB
Memory Warning but Small Live Bytes

Maybe I should move "creating UIImage" to c/c++ code? so that I don't have to worry about loading many images? Wonder if that's possible.
Or maybe use pool of memory for images since image size is all the same.

回答1:

It depends on a lot of factors, the device in question, the iOS version, what else is happening on the device at the same time, etc. Basically, you should take the warnings seriously whenever they arrive. Getting the warnings is not a problem. Doing nothing when you get them is a bad idea.

In my experience, 17Mb is on the low side of normal.



回答2:

Yes, it's normal. But working with memory on iOS devices is little bit tricky.

Firstly, you have to know amount of available memory - you can find some source code at http://adeem.me/blog/2009/04/01/get-the-amount-of-free-memory-available/ . Then make some allocate-free iterations with size lesser than was measured (this action forces another applications to free memory). After that, measure available memory again, and, you'll be surprised - size of available memory has been grown up.