开发者

CoreData memory management

I come from .NET world so memory management wasn't something I've given that much though in the past. So, this is the situation I'm in.. I have a method t开发者_如何学运维hat searches DB and returns some data back to view controller:

- (NSArray *)getSomeData
{
    NSMutableArray *myArray = [[NSMutableArray alloc] init];
    //search DB
    [myArray addObject:@"Here I'm adding some objects"];
    return myArray;
}

and in my view controller i have a global variable NSArray *myGlobalData to witch I add my DB data:

myGlobalData = [DataManager getSomeData];

And when I run my application with allocations or leaks there's a memory leak. How can I avoid this? I tried with autorelease but it didn't help. What's standard way of dealing with return of init/allocated objects?


You need....

 return [myArray autorelease];

But make sure you retain the array where you are using it....

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜