Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: retain recursively applied to objects?



No.

NSArray will retain each object as it is added to the array. It will send each object a release message when it ( the NSArray ) is deallocated.

Similarly NSObject will not forward retain messages to it's instance variables. They are retained once (in the setter) and released either when NSObject is deallocated (in your dealloc method) or when a new value is set for that ivar:

- (void) setSomeIvar: (NSObject*) object
{
[object retain]; // hold onto the new value for our ivar because we want to keep it around
[myIvarObject release]; // get rid of the old value for our ivar
myIvarObject = object; // assign the new value to the old
}


Later,
Guy

On 28-Apr-07, at 8:58 PM, Todd Heberlein wrote:

My questions are: (1) When an NSArray object is sent a "retain" message, is that message also sent to all the objects it contains? (2) When a subclass of an NSObject receives a "retain" message, does it forward the message to each instance variable in the object?

As example, suppose there is an EvilCorp, which has an array of showrooms, each showroom has an array of cars, and each car has an array of parts. When I send the "retain" message to the first array of showrooms, will that "retain" message be propagated all the way down to the car's parts objects? (pseudo code below is provided just for illustration purposes).

Thanks,

Todd



@interface EvilCorp : NSObject
{
	NSString * boss;
	NSMutableArray * showrooms;  // a list of showrooms
}
...
@ end



@interface Showroom : NSObject
{
	NSString * name;
	NSMutableArray * carList;	// list of cars
}
...
@end



@interface Cars : NSObject
{
	int	id_number;
	NSMutableArray * partsList;	// list of parts
}
...
@end

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
http://lists.apple.com/mailman/options/cocoa-dev/guy.english% 40gmail.com


This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >retain recursively applied to objects? (From: Todd Heberlein <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.