Hi,
I am fetching data from core data and putting it into an array using the following code:
However, when using this code however, Instruments shows memory leaks associated with
If I release records after I release request, my app crashes as records is called throughout my view controller. When and where should I release records? Should I use autorelease? If so, how?
I am fetching data from core data and putting it into an array using the following code:
Code:
/*
Fetch existing events.
Create a fetch request; find the Event entity and assign it to the request; add a sort descriptor; then execute the fetch.
*/
marblebeingdragged=YES;
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Child" inManagedObjectContext:_managedObjectContext];
[request setEntity:entity];
// Order the events by creation date, most recent first.
NSSortDescriptor *nameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:NO];
NSSortDescriptor *prizeDescriptor = [[NSSortDescriptor alloc] initWithKey:@"prize" ascending:NO];
NSSortDescriptor *neededDescriptor = [[NSSortDescriptor alloc] initWithKey:@"marblesneeded" ascending:NO];
NSSortDescriptor *colorDescriptor = [[NSSortDescriptor alloc] initWithKey:@"color" ascending:NO];
NSSortDescriptor *reachedDiscriptor = [[NSSortDescriptor alloc] initWithKey:@"prizereached" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:nameDescriptor,prizeDescriptor,neededDescriptor,colorDescriptor, nil];
[request setSortDescriptors:sortDescriptors];
[nameDescriptor release];
[colorDescriptor release];
[prizeDescriptor release];
[neededDescriptor release];
[reachedDiscriptor release];
[sortDescriptors release];
// Execute the fetch -- create a copy of the result.
NSError *error = nil;
records = [[self.managedObjectContext executeFetchRequest:request error:&error] retain];
[request release];
However, when using this code however, Instruments shows memory leaks associated with
Code:
records = [[self.managedObjectContext executeFetchRequest:request error:&error] retain];
If I release records after I release request, my app crashes as records is called throughout my view controller. When and where should I release records? Should I use autorelease? If so, how?