Re: End Of Method Releasing Order?
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