开发者

NSArray - Memory Leak how to?

开发者 https://www.devze.com 2023-02-01 06:50 出处:网络
I have function which return NSArray, but it\'s generating mem开发者_运维问答ory leak, since i can\'t release the array after return line how can I release it?

I have function which return NSArray, but it's generating mem开发者_运维问答ory leak, since i can't release the array after return line how can I release it? Thanks.

-(NSArray *)readDataFromDatabase
{

   return NSArray;

}


autorelease the array before returning:

- (NSArray*) readDataFromDatabase 
{
  // option 1: create an auto-released array
  NSArray* a = [NSArray arrayWithObjects: ...];
  return a;

  // option 2: autorelease manually
  NSArray* aa = [[[NSArray alloc] initWithObjects: ...] autorelease];
  return aa;
}


Check apple's docs for autorelease

0

精彩评论

暂无评论...
验证码 换一张
取 消