• 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: retaining arrays
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: retaining arrays


  • Subject: Re: retaining arrays
  • From: Stéphane Sudre <email@hidden>
  • Date: Fri, 21 Sep 2001 19:49:56 +0200

On vendredi, septembre 21, 2001, at 07:37 PM, Robert S Goldsmith wrote:

NSMutableArray *temp;
testClass *classInstance;

temp=[NSMutableArray arrayWithCapacity:2];
[temp addObject:@"String 1"];
[temp addObject:@"String 2"];

classInstance=[[testClass alloc] initWithArray:temp];


Then in testClass
-----
-(id)initWithArray:(NSArray *)theArray
{
myPointerToArray=theArray; //myPointerToArray is
//an instance variable
//if testClass


Now I find that this 'eats' the array in main (it seems to send it a release message or something). To stop a sigsegv error later on (like if I tried to release the array temp) I have to send temp a retain message at some point (either in main before it is passed to the init call of the instance of testClass or in the init method before the pointer is copied to myPointerToArray).

Why?

because.

it should be (IINTFFTT):

-(id)initWithArray:(NSArray *)theArray
{

if ( myPointerToArray!=nil)
{
[myPointer release];
}

myPointerToArray=[theArray retain]; //myPointerToArray is
} //an instance variable
//if testClass


  • Follow-Ups:
    • Re: retaining arrays
      • From: Ondra Cada <email@hidden>
References: 
 >retaining arrays (From: Robert S Goldsmith <email@hidden>)

  • Prev by Date: Re: NSSound--description forthcoming
  • Next by Date: Re: static typing (Learning Cocoa Chapter 13)
  • Previous by thread: retaining arrays
  • Next by thread: Re: retaining arrays
  • Index(es):
    • Date
    • Thread