Re: Memory Managment (copys??)
Re: Memory Managment (copys??)
- Subject: Re: Memory Managment (copys??)
- From: Will Mason <email@hidden>
- Date: Sat, 5 Feb 2005 13:52:17 -0800 (PST)
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
> NSMutableArray *array = [[NSMutableArray alloc] init];
> SOMEObject *object = [[SOMEObject alloc] init];
> for ( i = 0; i < 10; i++ ) {
> [object setSomeProperty: i];
> [array addObject: object];
> }
You're setting the same property on the same object ten times.
Therefore, it always comes out as the last value you set. Try this:
NSMutableArray* array = [[NSMutableArray alloc] init];
SOMEObject* object;
int i;
for (i = 0; i < 10; i++)
{
object = [[SOMEObject alloc] init];
[object setSomeProperty: i];
[array addObject: object];
[object release];
}
/* Do something with the array */
[array release];
Cheers,
Will
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden