• 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
memory management
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Prev by Date: iChat "Sort by..." animation
  • Next by Date: Re: iChat "Sort by..." animation
  • Previous by thread: Re: iChat "Sort by..." animation
  • Next by thread: RE: memory management
  • Index(es):
    • Date
    • Thread