memory management
memory management
- Subject: memory management
- From: "Ramakrishna Kondapalli" <email@hidden>
- Date: Tue, 13 Jan 2004 19:33:51 +0530
- Thread-topic: memory management
Hi,
I have a generic question regarding memory management in cocoa - ObjC.
Consider the following two pieces of code which are meant to do the same
thing.
Note that selectedCells method returns an NSArray* type and is being
released by its own controller class at some point of time in future.
The scope of myCells array is in the myMethod only.
Which of these 2 ways of using myCells array is better and why?
Sample 1
-(IBAction)myMethod:(id)sender
{
NSArray* myCells = [[[UIManagerClass defaultManager]
controllerForKeyWindow] selectedCells];
for(i=0;i<[myCells count];i++) {
MyCellInfo* info = [myCells objectAtIndex:i];
If([info isRelevant])
//do something
}
}
Sample 2
-(IBAction)myMethod:(id)sender
{
NSArray* myCells = [[[NSArray alloc] init] autorelease];
myCells = [[[UIManagerClass defaultManager] controllerForKeyWindow]
selectedCells];
for(i=0;i<[myCells count];i++) {
MyCellInfo* info = [myCells objectAtIndex:i];
If([info isRelevant])
//do something
}
}
Thanks & Regards,
Ramakrishna,
_______________________________________________
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.