RE: retain variables between classes
RE: retain variables between classes
- Subject: RE: retain variables between classes
- From: "Jonathan E. Jackel" <email@hidden>
- Date: Tue, 16 Dec 2003 15:18:02 -0500
Matt Gillette wrote:
>
Hi Jay,
>
>
I think copy will be your answer, but you should look at the
>
documentation to see how it works.
>
>
[array autorelease] //I'm not sure about this part
>
array = [inArray copy]; //Copy automatically
>
retains I think, so no
>
need to retain
>
You are right, but with a caveat. Yes, you should autorelease array before
you change what array points to. Otherwise you'll leak memory. Yes, you
shouldn't retain after a copy.
But copy does not always work. It works here because NSArray conforms to
the NSCopying protocol. Many classes (e.g., views) do not. You can't just
willy-nilly put copy everywhere you would otherwise put retain. That's not
what you said, of course, but you didn't seem too sure either.
Jonathan
_______________________________________________
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.