Convenience Vs init method (memory usage)

Total Post:13


 1278  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. 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.


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.