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 8281659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:06:39+00:00 2026-06-08T10:06:39+00:00

In my Garbage Collected Mac application I’m experiencing significantly high memory usage as a

  • 0

In my Garbage Collected Mac application I’m experiencing significantly high memory usage as a result of a helper function I put together to delete all Core Data entities of a particular type. Here’s the function, for reference:

- (void)deleteAllObjectsForEntity:(NSString *)entityDescription {
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:entityDescription inManagedObjectContext:self];
    [request setEntity:entity];
    [request setIncludesPropertyValues:NO];

    NSError *error = nil;
    NSArray *items = [self executeFetchRequest:request error:&error];
    [request release];

    // Delete all objects
    for (NSManagedObject *managedObject in items) 
    {
        [self deleteObject:managedObject];
    }

    // Should probably check for errors here
    [self save:&error];
    [self reset];

    // Suggest the garbage collector tries to tie up any loose ends
    [[NSGarbageCollector defaultCollector] collectIfNeeded];
}

By using heapshot analysis, I can see that each time I use the above function to remove all instances of my FileRecord entity, the heap grows by around 50MB. Memory which appears to never be recovered.

By using the -com.apple.CoreData.SQLDebug 1 launch argument I can see that the majority of this memory caused is caused by the (many) SELECT statements fired during my NSFetchRequest. It appears that each time these objects are selected, Core Data is firing the fault (and thus allocating memory). Obviously I don’t need these faults fired because I’m subsequently going to delete the object. Here’s an example of my console output:

CoreData: annotation: fault fulfilled from database for : 0x2002ed3e0 <x-coredata://17E6216A-C2FA-42A6-B8E4-5209CD1AB2CA/FileRecord/p117418>

CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZNORMALIZEDPATH, t0.ZSIZE, t0.ZFILENAME, t0.ZKIND, t0.ZNORMALIZEDFILENAME, t0.ZPATH FROM ZFILERECORD t0 WHERE  t0.Z_PK = ?

Whatever I do, I simply cannot get this memory to be relinquished. As you can see, I save and then reset my NSManagedObjectContext. Furthermore, I hint to the Garbage Collector that it should possibly attempt to collect any lingering data.

Unfortunately I’m working with an existing Core Data schema and, as such, cannot setup anything like cascade deletion rules. In any case, what am I doing wrong here?

  • 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-06-08T10:06:42+00:00Added an answer on June 8, 2026 at 10:06 am

    Perhaps the best way of solving this issue that I came across was to re-engineer my data model to create an intermediary object that contained a to-many relationship to all of the objects I was looking to remove. By setting the intermediary object’s delete rule to cascade, it was possible to delete the intermediary object and have it remove the remaining objects behind the scenes.

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

Sidebar

Related Questions

I'm making a non-garbage-collected MacFUSE Cocoa application, inside of which I want to use
Are there any good, portable, open-source, high-level, statically-typed, imperative, object-oriented, garbage collected, safe languages/runtimes
Will a DisplayObject be garbage collected if the only reference keeping it in memory
When are objects garbage collected in python? When is the memory released and does
When a classloader is garbage collected, are the classes loaded by it unloaded? When
my question is will garbage collector will free a memory if the variable allocated
Is objective-C garbage collected?
I am not sure how the user defined class objects are garbage collected. Do
In the below example program how many object will be garbage collected before executing
My developers and I are having an issue with objects being garbage collected in

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.