Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ahan.tm

macrumors regular
Original poster
Jun 26, 2011
141
0
Florida
Hi,

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

Nothing seems obviously wrong to me. Does the warning go away if you enable ARC? If not, then there is something more fundamental at play; if so, then it's fixed. :)

Reminds me a little bit of a diagram on my colleague's wall:
Universal Engineering Checklist - Answer these 2 questions: Does it move? Should it?
  • Yes and yes: do nothing
  • No and no: do nothing
  • Yes and no: duct tape
  • No and Yes: WD-40
 
Universal Engineering Checklist - Answer these 2 questions: Does it move? Should it?
  • Yes and yes: do nothing
  • No and no: do nothing
  • Yes and no: duct tape
  • No and Yes: WD-40
And if you erroneously answered Yes and No, but then realized it should be No and Yes, then WD-40 acts as a solvent for the duct tape adhesive.

If the error is in the other direction, then add Everclear and Shop Towels On A Roll to your kit of Universal Engineering Tools.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.