• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Retain count in non ARC
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Retain count in non ARC (From: Varun Chandramohan <email@hidden>)

  • Prev by Date: Re: NSSet + NSUndoManager / Core Data = ?
  • Next by Date: Re: NSSet + NSUndoManager / Core Data = ?
  • Previous by thread: Re: Retain count in non ARC
  • Next by thread: NSSet + NSUndoManager / Core Data = ?
  • Index(es):
    • Date
    • Thread