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

The Archive Base Latest Questions

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

Is any probability that a test object will be deallocated before [self saveContext] ?

  • 0

Is any probability that a test object will be deallocated before [self saveContext] ?

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Test" inManagedObjectContext:[self managedObjectContext]];
for (int i = 0; i < 10; i++) 
{
 Test *test = [[[Test alloc] initWithEntity:entity insertIntoManagedObjectContext:[self managedObjectContext]] autorelease];
 test.text = @"Text";
 test.index = [NSNumber numberWithInt:i];
}
[self saveContext];
  • 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-28T16:23:08+00:00Added an answer on May 28, 2026 at 4:23 pm

    No, unless under a couple of specific circumstances, and lets figure out why. Assuming this is on the main thread, before your selector is called, then the system will create a NSAutoreleasePool for you, before your function and then after.

    So, if when expanded, your code looks like this:

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Test" 
    inManagedObjectContext:[self managedObjectContext]];
    for (int i = 0; i < 10; i++) 
    {
     Test *test = [[[Test alloc] initWithEntity:entity insertIntoManagedObjectContext:[self managedObjectContext]] autorelease];
     test.text = @"Text";
     test.index = [NSNumber numberWithInt:i];
    }
    [self saveContext];
    [pool drain];
    

    entity would be released immediately after your function exits, which is after [self saveContext]. ARC would solve a lot of these problems, if you chose to enable it.

    Warning!

    Please note that this is not the actual code apple uses, the pool is only drained every frame, not every method, but when memory runs thin, the autorelease pool will automatically drain, so, IF your device is running out of memory, then theoretically, this could cause entity to be released early, but if that happens, you have other problems to worry about.

    Also note that when dealing with threads, you must create your own autorelease pool, the system will NOT do that for you. That is not what you appear to be doing here, but if the situation does occur, remember to wrap your selector in an @autorelease block.

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

Sidebar

Related Questions

Any good recommendations for a platform agnostic (i.e. Javascript) grid control/plugin that will accept
Let's say I want to determine the probability that I will upvote a question
Any good suggestions? Input will be the name of a header file and output
Any recommendations on grep tools for Windows? Ideally ones that could leverage 64-bit OS.
I have a letter trigram table that associates a probability with each trigram of
I'm looking for any tools that can give you code churn metrics (graphs and
The YAGNI principle states that you shouldn't focus on providing functionality before you needed
i need to test if any of the strings 'hello', 'i am', 'dumb' exist
I am trying to create a application that will figure out how to find
I am trying to update a Entity that is an OptionSetValue, the values it

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.