paxx
paxx

Reputation: 1079

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 that 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?

Upvotes: 1

Views: 222

Answers (1)

Simon Lee
Simon Lee

Reputation: 22334

You need....

 return [myArray autorelease];

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

Upvotes: 1

Related Questions