Re: retain variables between classes
Re: retain variables between classes
- Subject: Re: retain variables between classes
- From: John Randolph <email@hidden>
- Date: Tue, 16 Dec 2003 13:39:07 -0800
On Dec 16, 2003, at 9:54 AM, Jay Rimalrick wrote:
I have two classes MainClass and AClass
AClass has a method (with data item array)
-(void)setInfo: (NSMutableArray *)inArray
{
[array release];
[inArray retain];
array = inArray; // also tried array = [inArray
mutableCopy]
}
Consider for a moment, what happens if the array I hand to this method
is the same one you've already got?
That first message, [array release], can destroy it immediately.
If you just reverse the order of those two messages, then you'll be
alright: retain the one I'm handing you, release the one you've got,
and then assign the pointer value.
Another thing to consider here, is whether you want your own copy of
the things in inArray. What if something else modifies the contents of
inArray?
-jcr
John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.