• 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: retain variables between classes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Re: retain variables between classes (From: Matt Gillette <email@hidden>)

  • Prev by Date: Re: retain variables between classes
  • Next by Date: Re: retain variables between classes
  • Previous by thread: Re: retain variables between classes
  • Next by thread: Re: retain variables between classes
  • Index(es):
    • Date
    • Thread