Jennifer Morgan

Total Post:13

Posted by  Jennifer Morgan
 872  View(s)
Rate this:

I tried to create UIImageView object using Convenience and init method, after when I try to go back and check the memory usage that are increases after creation of both methods, the memory usage under the convenience method takes 10MB to 7MB and init method takes from 10MB to 4MB immediately both examples are here:
Convenience Method:

imageView.image = [UIImage imageWithData:[downloads dataAtIndex:0]];

init Method:

UIImage *aImage = [[UIImage alloc] initWithData:[downloads dataAtIndex:0]];
imageView.image = aImage;
[aImage release];

I also waited and interacted with the app to give time on releasing on the convenience method's autorelease. But it didn't drop much.
Other than the autorelease vs release, what else contributed the difference?

  1. Tarun Kumar


    Re: Convenience Vs init method (memory usage)

    The only difference that could be causing this is that imageWithData: doesn't use the system image cache, while initWithData: does. So maybe the image that's made with the initializer can release it's image data when it receives a memory warning since it can go back to the system cache, while the one that's created by the convenience method can't.
    It is advisable to wrap memory intensive operations inside of an NSAutoreleasePool block if you will be making heavy use of them.



Enter your email address here always to be updated. We promise not to spam!