• 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 I retain a variable returned from this accessor?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Should I retain a variable returned from this accessor?


  • Subject: Re: Should I retain a variable returned from this accessor?
  • From: Ken Thomases <email@hidden>
  • Date: Tue, 12 Aug 2008 20:54:03 -0500

On Aug 12, 2008, at 11:51 AM, Brian Stern wrote:

On Aug 11, 2008, at 10:51 PM, Peter N Lewis wrote:

[newTodo release] is not [newTodo autorelease]. So it may immediately call dealloc and dealloc the uid returned by by [newTodo uid]. To avoid this, you could do:

Not really. This line:

	// Add the todo to my iCal calendar
	[[myCalendar todos] addObject:newTodo];


would appear to add newTodo to an NSMutableArray, which implicitly retains it. So this method retains newTodo twice but releases it once. As a result the todoUid string won't be released, as you fear, upon sending release to newTodo.

If [myCalendar todos] really is _known_ to be a container that retains its elements, that's correct. From the original context, though, it seems it might have been a scripting proxy for the to-do items contained in a calendar in iCal -- that is, the addObject: actually communicates with another application. In that case, there is no reason to believe that newTodo is effectively retained.


Cheers,
Ken
_______________________________________________

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


  • Follow-Ups:
    • Re: Should I retain a variable returned from this accessor?
      • From: Peter N Lewis <email@hidden>
References: 
 >Should I retain a variable returned from this accessor? (From: Sean DeNigris <email@hidden>)
 >Re: Should I retain a variable returned from this accessor? (From: "Kyle Sluder" <email@hidden>)
 >Re: Should I retain a variable returned from this accessor? (From: Peter N Lewis <email@hidden>)
 >Re: Should I retain a variable returned from this accessor? (From: Brian Stern <email@hidden>)

  • Prev by Date: Xcode Template Example
  • Next by Date: Re: Accessing memory of another application?
  • Previous by thread: Re: Should I retain a variable returned from this accessor?
  • Next by thread: Re: Should I retain a variable returned from this accessor?
  • Index(es):
    • Date
    • Thread