Re: Memory Managment (copys??)
Re: Memory Managment (copys??)
- Subject: Re: Memory Managment (copys??)
- From: Roarke Lynch <email@hidden>
- Date: Sun, 6 Feb 2005 11:16:59 -0500
On Feb 5, 2005, at 4:52 PM, Will Mason wrote:
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];
This code will leak. You should replace the first line in the for loop
with:
object = [[[SOMEObject alloc] init] autorelease];
You need to make sure that any local objects you use are (retain,
alloc, copy) / (autorelease, release) balanced.
Roarke Lynch
-------------------------------
email@hidden
_______________________________________________
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