NSArray - Memory Leak how to?
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
精彩评论