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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:16:50+00:00 2026-05-26T10:16:50+00:00

I know this is a common problem, so I need an explanation so I

  • 0

I know this is a common problem, so I need an explanation so I don’t keep having this problem. In my header file, I have defined a UIAlertView and retained it as shown:

@interface myController {
    UIAlertView *alert;
}

@property (nonatomic, retain) UIAlertView *alert;

In my implementation, I use and reuse this alert as follows:

@synthesize alert;

 ...

    if (self.alert != nil) {
        [self.alert release];
    }

    self.alert = [[UIAlertView alloc] initWithTitle:title 
                                       message:message
                                      delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles: @"Ok To Send", nil];

    [self.alert show];

I also release this in my dealloc.

So, I’ve heard the golden rule on memory management, but I apparently don’t understand it. The golden rule says that you must never release an object that you have not either retained or obtained via alloc. You must always eventually release an object that you have either retained or obtained via alloc.

I retained it in the header file, so I eventually must release it in the dealloc. In my implementation, I perform an alloc of the alert object more than once, so each time I get ready to re-alloc it, I release the old one.

Please help me understand what I am misunderstanding.

  • 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-26T10:16:51+00:00Added an answer on May 26, 2026 at 10:16 am

    The @property with retain specified is implemented something like this…

    -(void)setAlert:(UIAlertView*)alert
    {
            if (self->alert != alert)
            {
                    [self->alert release];
                    self->alert = [alert retain];
            }
    }
    

    So by assigning a new value to the property, the property will handle the release of the previous value… so when you manually release it, you’re over-releasing.

    Also, since you have the @property set to retain, you should autorelease before assigning to the property:

    self.alert = [[[UIAlertView alloc] initWithTitle:title 
                                             message:message
                                            delegate:self cancelButtonTitle:@"Cancel"  
                                   otherButtonTitles: @"Ok To Send", nil] autorelease];
    
    [self.alert show];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm sure this is a common problem, I don't know if there is a
I stumbled across this before and I know it is a common problem. One
I know this is a common convention, but what does the k in variable
I know this is a common error, but bear with me. I've pursued the
I know this isn't strictly a programming question but y'all must have experienced this.
I know that this problem is caused by the sleep or wait calling on
I know jquery/ajax in IE is a common problem. There is a lot of
I have come across what must be a common problem. When I have an
I know it is a common problem, I googled a lot and seems get
I am sure that this must be quite a common problem so I would

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.