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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:09:46+00:00 2026-05-16T17:09:46+00:00

Instruments is pointing out that this is a memory leak, however I’m unsure how

  • 0

Instruments is pointing out that this is a memory leak, however I’m unsure how to release it properly, or when it should be released.
Is there a better convention for assigning properties with new objects that are only needed inside a loop? The specific line is the expense.addedDate = [NSDate new];.

- (void) addObjects:(NSString *)itemDescription withItemAmount:(NSString *)itemAmount {
// Add a new expense to the persistent store.
NSString *expenseDescription = itemDescription;
NSString *expenseAmount = itemAmount;
if (!expenseDescription.length || !expenseAmount.length) {
    UIAlertView *invalidEntry = [[[UIAlertView alloc] initWithTitle:@"Invalid Entry" 
                                                            message:@"You must include a description and cost." 
                                                           delegate:self 
                                                  cancelButtonTitle:@"OK" 
                                                  otherButtonTitles:nil] autorelease];
    [invalidEntry show];
} else {
    Expense *expense = (Expense *)[NSEntityDescription insertNewObjectForEntityForName:@"Expense"
                                                                inManagedObjectContext:self.managedObjectContext];
    expense.addedDate = [NSDate new];
    expense.itemDescription = expenseDescription;
    expense.cost = [NSNumber numberWithInt:[expenseAmount intValue]];

    NSError *error;
    if (![self.managedObjectContext save:&error]) {
        NSLog(@"Error %@", [error localizedDescription]);
        UIAlertView *errorSave = [[[UIAlertView alloc] initWithTitle:@"Unable to Save!" 
                                                            message:@"Money manager was not able to save this entry." 
                                                           delegate:self 
                                                  cancelButtonTitle:@"OK" 
                                                  otherButtonTitles:nil] autorelease];
        [errorSave show];
    } else {
        NSLog(@"Saved Expense to Database.");
    }
}
}
  • 1 1 Answer
  • 1 View
  • 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-16T17:09:47+00:00Added an answer on May 16, 2026 at 5:09 pm

    I think you don’t want to use the new selector, as it is not auto-released. If you’re looking for a default, current timestamp, autoreleased NSDate object, you should use:

    expense.addedDate = [NSDate date];
    

    For the record,

    [NSObject new]
    

    is equivalent to

    [[NSObject alloc] init]
    

    Apple’s docs on the new method

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

Sidebar

Related Questions

Instruments is showing that i get a memory leak right there: -(id) copyWithZone: (NSZone
Instruments tells me there's a mem leak in this code, but I can't seem
I'm getting an instruments Memory Leak with this iPhone 3.0 SDK code. I'm using
does an entry in Instruments leaked block during application running imply memory leak? That
Instruments tools says this is a leak, any ideas? I release the variable object
While using Instruments, it seems like there is a leak coming from this method
Instruments tells that there are misaligned images which are animated by core animation. What
Using Instruments, I keep on getting pointed to a memory leak with a UIImage.
I'm really pulling my hair out on this one, it seems that I'm having
This is what Instruments is pointing to. students = [[NSMutableArray alloc] initWithArray:[course.students allObjects]]; I'm

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.