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

  • SEARCH
  • Home
  • 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 6123897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:04:14+00:00 2026-05-23T16:04:14+00:00

I’m having a memory leak in the following code. I got 87.5% of the

  • 0

I’m having a memory leak in the following code. I got 87.5% of the memory leak before Instruments itself crashed. Maybe one of you can tell me what is wrong with this code. Do I need to be releasing anything in here? Thanks.

- (void)browseSSviewControllerDidFinish:(browseSSviewController *)controller {
<SNIP>
      MANAGED_OBJECT_1 = [self newFormatFromFormat:MANAGED_OBJECT_2];
<SNIP>
}

- (Format *)newFormatFromFormat:(Format *)formatToCopy {

    NSLog(@"making new format that's a copy");
    Format *thisNewFormat = [self newBlankFormat];
    [self updateFormat:thisNewFormat withNumbersFromFormat:formatToCopy];
    return thisNewFormat;
}

-(void)updateFormat:(Format *)formatToCopyTo withNumbersFromFormat:(Format *)formatToCopyFrom {
    NSLog(@"copying formats");
    formatToCopyTo.x = formatToCopyFrom.x;
    formatToCopyTo.y = formatToCopyFrom.y;
    formatToCopyTo.z = formatToCopyFrom.z;
    formatToCopyTo.a = formatToCopyFrom.a;
    formatToCopyTo.n = formatToCopyFrom.n;
    formatToCopyTo.u = formatToCopyFrom.u;
    formatToCopyTo.s = formatToCopyFrom.s;
}

- (Format *)newBlankFormat {

    NSLog(@"making new blank format");
    gfghfAppDelegate *del = (gfghfAppDelegate *)[UIApplication sharedApplication].delegate;
    NSManagedObjectContext *MOC = del.managedObjectContext;
    NSPersistentStoreCoordinator *PSC = [MOC persistentStoreCoordinator];
    NSManagedObjectModel *MOM = [PSC managedObjectModel];
    NSEntityDescription *entity = [[MOM entitiesByName] objectForKey:@"Format"];
    Format *thisNewFormat = [[NSManagedObject alloc] initWithEntity:entity insertIntoManagedObjectContext:MOC]; 
    thisNewFormat.slot = [NSNumber numberWithInt:-1];
    NSLog(@"slot = %@",thisNewFormat.slot);
    return thisNewFormat;
}

Here is the 87.5% of the leak that I was able to get out of my backtrace before Instruments crashed:

+0xc7 calll DYLD-STUB$$objc_msgSend = 87.5%

I didn’t use mutableCopy to copy my MANAGED_OBJECTs because it just didn’t work.

  • 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-23T16:04:14+00:00Added an answer on May 23, 2026 at 4:04 pm

    I rewrote the newBlankFormat:thisNewFormat method and used the “insertNewObjectForEntityForName:inManagedObjectContext:” convenience method of NSEntityDescription (see “Creating, Initializing, and Saving a Managed Object” in the “Creating and Deleting Managed Objects” chapter of Apple’s “Core Data Programming Guide”).

    I think my problem initially that I was using “NSManagedObject alloc” with “initWithEntity:insertIntoManagedObjectContext”, which does not make an auto-released object. It would leak even when I would release it myself from another method using a “release” later on the returned value using the instance variable that got the return value from this method. However, whether or not I put in a “retain” around the malloc, the release count wasn’t being incremented I don’t believe, since it’s not a proper init function? I’m not sure why.

    But I don’t care because the following revision fixed the leak, and as it turns out, is what Apple recommended to use anyway (I think I was using the old code from an example project or something).

    Here is the revision that appears to have fixed the leak, in the new version of the “newBlankFormat:thisNewFormat” function:

    - (Format *)newBlankFormat:(Format *)thisNewFormat {
                NSLog(@"making new blank format");
                gfghfAppDelegate *del = (gfghfAppDelegate *)[UIApplication sharedApplication].delegate;
                NSManagedObjectContext *MOC = del.managedObjectContext;
                //[MOC reset]; don't do this, it will erase MANAGED_OBJECT_2
                thisNewFormat = [NSEntityDescription insertNewObjectForEntityForName:@"Format" inManagedObjectContext:MOC]; //this is much better than using the malloc variety
                thisNewFormat.slot = [NSNumber numberWithInt:-1];
                NSLog(@"slot = %@",thisNewFormat.slot);
                return thisNewFormat;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.