• 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: 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.

References: 
 >retain variables between classes (From: "Jay Rimalrick" <email@hidden>)

  • Prev by Date: Re: 'WebKit/WebKit.h' not found
  • Next by Date: Required InfoPlist entries
  • Previous by thread: RE: retain variables between classes
  • Next by thread: Re: retain variables between classes
  • Index(es):
    • Date
    • Thread