• 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: End Of Method Releasing Order?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: End Of Method Releasing Order?


  • Subject: Re: End Of Method Releasing Order?
  • From: Wade Tregaskis <email@hidden>
  • Date: Mon, 01 Jun 2009 18:06:04 -0700

does it matter which order objects are released at the end of a
method?  example:

-=-=-=-=-

- (void)applicationWillTerminate:(NSNotification *)notification
	{
	FourLines *fourLines = [[FourLines alloc] init];
	fourLines.field1 = field1.text;
	fourLines.field2 = field2.text;
	fourLines.field3 = field3.text;
	fourLines.field4 = field4.text;

	NSMutableData *data = [[NSMutableData alloc] init];
	NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc]
initForWritingWithMutableData:data];
	[archiver encodeObject:fourLines forKey:kDataKey];
	[archiver finishEncoding];
	[data writeToFile:[self dataFilePath] atomically:YES];

	[archiver release];
	[data release];
	[fourLines release];
	}

In the case above, and in general, no - most retains you'll have on other objects are for your own use, and if they keep a reference to anything themselves, they are responsible for retaining it on their own behalf. If, however, you have a retain on something on behalf of something else - e.g. you hand a struct to some function, which contains a pointer to an object that you have to retain on its behalf - then the order can matter, though for better or worse such scenarios often allow you to get away with it, whether coincidentally or luckily.


Wade
_______________________________________________

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: 
 >End Of Method Releasing Order? (From: Chunk 1978 <email@hidden>)

  • Prev by Date: Re: End Of Method Releasing Order?
  • Next by Date: Re: NSToolbar: notification of change?
  • Previous by thread: Re: End Of Method Releasing Order?
  • Next by thread: Re: Dynamically getting the type of ivars
  • Index(es):
    • Date
    • Thread