• 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: Should objects returned by indirection be autoreleased
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Should objects returned by indirection be autoreleased


  • Subject: Re: Should objects returned by indirection be autoreleased
  • From: Lon Giese <email@hidden>
  • Date: Fri, 12 May 2006 20:23:08 -0700


No don't assume that... the doc for setRepresentedObject: does not say that NSCell will retain it... so it wont... if you dont explicitly release the it you will have a memory leak... things like targets, delegates and such are not retained by the object you pass it to... The hard and fast rule is if you create it ( any init method or any copy method ) or retain it then you have to release it... If you didn't create it or retain it then you MUST NOT release it. NSArray for example will retain objects added to it, but the rule still holds... If you create an object (retain count 1) then add it to a NSArray now the object has a retain count of 2, when you release the array, NSArray will release the object, now it has a retain count of 1... it is still occupying memory... So weather or not NSCell retains the represented object or not, you must still release it yourself if you created it (with init...) or copied it.... However NSCell does not retain the object so if you release the object while NSCell still has it's id you'll likely get a stern warning or crash when NSCell tries to send a message to it... clear as mud? you'll figure it it after you track down several crashes in the autorelease pool... when the autorelease pool crashes you know an object was released too many times...




On May 12, 2006, at 6:42 PM, Eric wrote:

Thanks for all your response. Here's another memory related problem I've
just hit upon:


NSCell has the property "representedObject". If I subclass NSCell and set
and use the property from within my subclass (by calling
setRepresentedObject:), then can I assume it will be automatically
deallocated in [super dealloc]? In other words, I can just use this
property without doing anything.


Thanks again,
Eric
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden


This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Should objects returned by indirection be autoreleased
      • From: Bill Bumgarner <email@hidden>
References: 
 >Should objects returned by indirection be autoreleased (From: Eric <email@hidden>)
 >Re: Should objects returned by indirection be autoreleased (From: Jim Correia <email@hidden>)
 >Re: Should objects returned by indirection be autoreleased (From: Jim Correia <email@hidden>)
 >Re: Should objects returned by indirection be autoreleased (From: Eric <email@hidden>)

  • Prev by Date: Implementing -willDisplayCell... delegate method for NSMatrix
  • Next by Date: Re: Should objects returned by indirection be autoreleased
  • Previous by thread: Re: Should objects returned by indirection be autoreleased
  • Next by thread: Re: Should objects returned by indirection be autoreleased
  • Index(es):
    • Date
    • Thread