Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 916525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:04:02+00:00 2026-05-15T18:04:02+00:00

I desperately need help with a memory leak in my iPhone app. The app

  • 0

I desperately need help with a memory leak in my iPhone app. The app is ready to submit to the app store, is stable, has no memory leaks at all in iPhone simulator or Clang … but seems riddled with them on my iPod Touch.

They all seem to stem from managedObjectModel when I’m trying to retrieve data from Core Data.

The Core Data code in my app was automatically created by Xcode a while back, I’ve noticed that the code has since changed when you get xcode to generate it … I’ve tried with the old and new but it makes no difference.

If I comment out the following code, the problem goes away … can anyway see what’s wrong with it? I’ve spent 9 hours on this so far and just can’t figure it out!

NSString *entityForName = [[NSString alloc] initWithString:@"OfflineSettings"];

NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:entityForName inManagedObjectContext:[self managedObjectContext]];
[request setEntity:entity]; 

[entityForName release];

NSSortDescriptor *sortById = [[NSSortDescriptor alloc] initWithKey:@"Id" ascending:YES];
[request setSortDescriptors:[NSArray arrayWithObject:sortById]];
[sortById release]; 

NSError *error;
NSMutableArray *mutableFetchResults = [[[self managedObjectContext] executeFetchRequest:request error:&error] mutableCopy];
if (mutableFetchResults == nil) {
    // Handle the error.
    NSLog(@"Error fetching");
}

int intId = -1;

if ([mutableFetchResults count] == 0) {
    TTDERROR(@"No id has been saved to offline settings");      
} else {    
    OfflineSettings *offlineSettings = (OfflineSettings *)[mutableFetchResults objectAtIndex:0];        
    intId = [offlineSettings.Id intValue];
}

[mutableFetchResults release];
[request release];

The leak specifically seems to be on this line:

NSMutableArray *mutableFetchResults = [[[self managedObjectContext] executeFetchRequest:request error:&error] mutableCopy];

.. and the code for [self managedObjectContext] is as follows in case it helps ..

- (NSManagedObjectContext *)managedObjectContext {

    if (managedObjectContext_ != nil) {
        return managedObjectContext_;
    }

    NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
    if (coordinator != nil) {
        managedObjectContext_ = [[NSManagedObjectContext alloc] init];
        [managedObjectContext_ setPersistentStoreCoordinator:coordinator];
    }
    return managedObjectContext_;
}

I’m really at a loss, so I would be so grateful for some help!

Steven

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T18:04:03+00:00Added an answer on May 15, 2026 at 6:04 pm

    You don’t need the mutable copy. executeFetchRequest: returns an autoreleased static array and you’re not mutating the array. (I keep seeing this. Must be in an example somewhere.) Likewise, creating the entityForName NSString is pointless. Just put the string literal in the entityForName: to eliminate another possible source of error.

    Niether of these are the likely source of the leak but you should remove them anyway.

    As a rule of thumb, if you have troubles on device but not simulator or on one hardware but not others, then the problem is in a library/framework that is not properly compiled for the hardware where the error occurs. There really isn’t any type of coder error that leaks in one environment but not others. When we make a mistake, it’s universal.

    It’s also possible for resources such as images and sounds to behave differently because different devices use different graphics and audio hardware. That, however, is rather rare.

    If you run the code through Instruments it should tell you exactly what object is leaking.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not familiar with this website but I am desperately seeking help with
I've been trying desperately to get my application (15 C# dlls and 1 C++/CLI
I'm desperately searching for a tool allowing me to copy documents with their old
I'm starting to get a bit desperate in my attempts to get a ruby

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.