Re: Retain count in non ARC
Re: Retain count in non ARC
- Subject: Re: Retain count in non ARC
- From: John McCall <email@hidden>
- Date: Fri, 04 Apr 2014 13:33:58 -0700
On Apr 3, 2014, at 8:22 PM, Varun Chandramohan <email@hidden> wrote:
> Interestingly, the static code analysis find the call of "retain" as a leak. How do I address this issue? What is correct way to rewrite this code to make static analyser understand that I will be releasing the resource? If I removed the retain count, the warning goes away but it contents is freed and I crash.
As Graham says, the problem is that you’ve declared ‘contents’ assign, but you're actually working with it like a strong property: you’re establishing an invariant that the object in that property is held at +1. Presumably you even release it in your -dealloc. If anything else ever assigns to this property, it’ll have to manually release the current value and then pass a object at +1 into the setter. (If nothing else ever assigns to this property, you should make it readonly.)
Just make it a strong property and either (1) pass the value to the setter at +0 or (2) make the property readonly and assign the +1 value directly to the ivar.
John.
_______________________________________________
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