Re: Memory Leaks and ARC
Re: Memory Leaks and ARC
- Subject: Re: Memory Leaks and ARC
- From: Quincey Morris <email@hidden>
- Date: Wed, 23 Apr 2014 10:26:16 -0700
On Apr 23, 2014, at 03:01 , Dave <email@hidden> wrote:
> If I changed the names of commandDownloadImageWithFileURLString to be newCommandDownloadImageWithFileURLString, this would cause it to release myImage on each iteration rather than using Autorelease?
It would remove one — and perhaps the only — reason for ARC to use autorelease, but there’s no way of knowing whether there are others, hidden from you. For example, even if you create a new image using some alloc/init that returns the created object with +1 ownership, it may have already been autoreleased before it gets back to you.
The outcome is also going to vary with the version of clang you compiled with, and the OS version you’re running on. The current clang already uses autorelease less often than the original implementation, and Cocoa classes may get converted from MRR to ARC gradually over OS releases.
It seems to me that the best practice is:
— Return objects with +1 ownership when semantically appropriate (when the caller gets an object that is conceptually new).
— Investigate memory usage with Instruments, preferably on supported older OS versions too.
— Bracket problem areas with @autoreleasepool{} only you’ve identified a problem area with Instruments.
— Don't gratuitously insert @autoreleasepool{} in loops “just for safety”.
> Is there anyway of telling if an Object is in “autorelease” state? I mean just for testing, I wouldn’t rely on this in shipping code.
I don’t think so.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden