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

The Archive Base Latest Questions

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

I ran instrument in xcode4 and it told me there were two leaks in

  • 0

I ran instrument in xcode4 and it told me there were two leaks in the following code (noted by ****). I thought I had taken care of memory release with code at pt. A and pt. B.

I read through some related topics here but still couldn’t figure out why and how to fix them.

Another question is whether the release at pt. A is necessary.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //Get the dialog id
    NSDictionary *rowData = [dialogs objectAtIndex:indexPath.row];
    NSInteger dialogId = [[rowData objectForKey:@"id"] intValue];

    DialogViewController *detailViewController = [[DialogViewController alloc] initWithNibName:@"DialogViewController" bundle:nil];
    detailViewController.dialogId = dialogId;
    NSString *title = [NSString stringWithFormat:@"%d. %@", [[rowData objectForKey:@"id"] intValue], [rowData objectForKey:@"title"]];
                ****** i     6.8%
    [detailViewController.dialogTitle release];             // pt. A
    detailViewController.dialogTitle = [title retain];

    [self.navigationController pushViewController:detailViewController animated:YES];
                ****** i 93.2%
    [detailViewController release];                         // pt. B

}

Thanks much in advance!
Lu

  • 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-23T07:46:29+00:00Added an answer on May 23, 2026 at 7:46 am

    Whether the release/retain calls are necessary at Point A depend on how you defined your dialogTitle property.

    If you defined it as @property (retain) then you don’t need to release the old value or retain the new value because when you assign a value to a (retain) property, it is automatically retained. Also when you assign a new value to a (retain) property, the old value is released, so you don’t have to do the release either. All you would need in this case is:

    detailViewController.dialogTitle = title;
    

    If you defined dialogTitle as (assign) then you DO need to do the release/retain in Point A.

    As for Point B, you do need to release there because if you don’t, your detailViewController object will never get deleted. When it is alloc/inited, it gets a retain count of 1. When you push the view controller, it gets retained (so now has a retain count of 2). Then you release at the end of the method and it’s retain count goes down to 1. Then, when the navigation controller that contains it is dismissed, it will get released again, it’s retain count will go to 0 and it will get deleted.

    As an alternative to releasing the detailViewController at the end of the method, you could just autorelease it when you alloc/init it and remove the release at the end of the method. By autoreleasing it, you are essentially marking it to be released automatically the next time the autorelease pool is cleared out (which will be soon after this method exits)

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

Sidebar

Related Questions

I ran across the following code in Ely Greenfield's SuperImage from his Book component
A lot of my memory leaks are coming from this code that recognizes swipes.
Ran accross the following code in an article and didn't think it was standard
I'm working on a project that requires extreme care with memory. I ran the
Ran across this line of code: FormsAuth = formsAuth ?? new FormsAuthenticationWrapper(); What do
I ran across this situation this afternoon, so I thought I'd ask what you
I ran Instruments on my iPad app to check for leaks. It found several
I ran into this code on Wikipedia : (define (pyth x y k) (*
Ran into a bit of an issue with some jQuery code, but in essence,
Ran the new Lint tool against my code. It came up with a lot

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.