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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:54:00+00:00 2026-05-25T09:54:00+00:00

I have an ivar that is a UIPopoverController. When it gets dismissed, I want

  • 0

I have an ivar that is a UIPopoverController. When it gets dismissed, I want to clean up memory. I call the following method when the popover gets dismissed, or if the user pressed the BarButtonItem when the popover is already being presented to the user.

- (void)popoverCleanup:(UIPopoverController *)popoverController {
    popoverController.delegate = nil;
    popoverController = nil;
}

I set a breakpoint and tried following the code and looking at the memory. I see that my ivar Popover and the method parameter popoverController both point to the same memory address. When I hit the first line, I see the delegate set to nil on both the Popover and popoverController parameter. When I reach the end of the method however, I see only popoverController’s memory set to nil, whereas the ivar Popover does not get set to nil. Is there a reason for this?

Thanks.

  • 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-25T09:54:01+00:00Added an answer on May 25, 2026 at 9:54 am

    By doing this, you are just saying you don’t want to hold a popoverController pointer, no matter to what it points. Nothing get’s released here. Proper way to release a popover is implementing it’s delegate method for dismissing and release it there.

    - (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
        [popoverController release];
    }
    

    Keep in mind that setting an ivar to nil doesn’t release the object that ivar was pointing to, it usually leaks it. You can only do that with copied or retained properties because they work so that the retain or copy the new value (nil, which does nothing when retained or copied as it’s not really an object) and release the old one. You should only set the ivar to nil after releasing it so that if you accidentally send it a message later, you don’t crash for accessing released memory.

    Edit: also keep in mind that there is really no need for ivar if you only want to present a popover and release it. Just create a local variable and present a popover. Once delegate method gets called it will have a pointer to the popover object, no need to keep ivar just for that. Only case where you would need an ivar for popover is if you wanted to create it and present it multiple times, then release it when done with it forever, like when leaving view controller from which you presented it.

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

Sidebar

Related Questions

[I have read the Cocoa memory management rules, but still want to be certain,
I have an object ivar foo inside a NSManagedObject subclass bar that I need
I have a very simple Person class that has a ivar called name (
I wanna have an if statement that's condition is when a float ivar is
Have you managed to get Aptana Studio debugging to work? I tried following this,
I have a xib. the xib has a button that swaps another xib. the
I have an object that has several properties. If I have a pointer to
I have a root UIViewController subclass that has a UITabBar, (I'm not using UITabBarController)
I have an ivar, keys which is an NSMutableArray containing 50 strings. When my
I have numerous classes that use the various NSDictionary/NSArray collection classes as ivars but

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.