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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:46:39+00:00 2026-05-27T11:46:39+00:00

In the following code I alloc a UIPopoverController. Obviously I am not releasing it

  • 0

In the following code I alloc a UIPopoverController. Obviously I am not releasing it here because I am not sure where I should properly release it without a crash.

Where should I release it?

- (IBAction)photoLibraryiPad {
    if ([UIImagePickerController isSourceTypeAvailable:
         UIImagePickerControllerSourceTypeSavedPhotosAlbum])
    {
        UIImagePickerController *imagePicker =
        [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.sourceType =
        UIImagePickerControllerSourceTypePhotoLibrary;

        self.popoverController = [[UIPopoverController alloc]
                                  initWithContentViewController:imagePicker];
        popoverController.delegate = self;
        [self.popoverController presentPopoverFromRect:myButton.frame inView:self.view
                              permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
        [imagePicker release];
    }
}

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-27T11:46:40+00:00Added an answer on May 27, 2026 at 11:46 am

    You should keep a reference to it in your view controller and release it when you’re done.

    But in that case, you’re both setting the property and creating a already-retained object.

    Here, [[UIPopoverController alloc]initWithContentViewController:imagePicker]; creates a retained object that you must release.

    But you’re setting the property popoverController to that value, and the setter of that property probably retain that value.

    You’re retaining the popover twice and never releasing it.

    You should :

    UIPopover* popover = [[UIPopoverController alloc]
                                      initWithContentViewController:imagePicker];
    self.popoverController = popover;
    [popover release];
    

    And when you’re done with the popover :

    self.popoverController = nil;
    

    You should probably review your memory management rules to make that clear or use ARC.

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

Sidebar

Related Questions

The following code: listViewPopoverControllerOL = [[UIPopoverController alloc] initWithContentViewController:myBranchesListViewPage]; produces the following crash in iPad2
The following code should work, right? ViewController2 *childView = [[ViewController2 alloc] initWithNibName:@ViewController2 bundle:nil]; [self.navigationController
i have the following code... DistanceInformation *distanceInformation=[[DistanceInformation alloc]init]; NSArray *latLongArray=[distanceInformation calculateDistance]; [distanceInformation release]; NSLog(@lat
The following code: [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:mapURL]] returns an instance of NSConcreteData as opposed to
The following code: NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateFormat:@MM/dd]; NSDate *newTime
I have the following code to create a UIPickerView: pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0f,
I am running the following code in tableView:cellForRowAtIndexPath: File *file = [[File alloc] init];
I am using the following code for UIImagePicker, UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
Why doesn't the following code work? MyViewController *viewController = [[MyViewController alloc] init]; [myWindow addSubview:viewController.view];
I'm creating a color object using the following code. curView.backgroundColor = [[UIColor alloc] initWithHue:229

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.