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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:36:57+00:00 2026-05-11T09:36:57+00:00

Similar to the known memory leak issue regarding creating and destroying an instance of

  • 0

Similar to the known memory leak issue regarding creating and destroying an instance of the UIImagePickerController, I’m finding similar problems regarding instances of the UIViewController class. The recommended way to use the UIImagePickerController is to create the instance once and keep it around for the lifetime of the application, eventhough this will use up memory that you may need elsewhere.

The situation I’m dealing with involves 2 instances of the UIViewController class. On start up, the first instance is created and its view is added to another ‘main’ UIViewController class that is part of the MainWindow.xib. On this first instance is an ‘info’ button that when tapped, switches to a new instance of the UIViewController class (if it hasn’t already been created). The ‘main’ UIViewController manages this switching with the usual flip animation. The basic setup can be seen in the ‘Beginning iPhone Development: Exploring the iPhone SDK’ book by Dave Mark.

The problem that arises is that once the ‘info’ button is tapped the very first time, memory is allocated to the new second UIViewController instance and it is not released until the application ends. Due to the number of elements on this info view, it uses approximately 1MB of memory once instantiated and its view is added to the superview. Any attempts to consistently destroy and recreate this instance results in a memory leak, similar to the one that exists if you try to do the same thing to instances of the UIImagePickerController class. I suspect that the root cause is the same between the two classes.

The crux of my problem involves needing to have as much memory freed before I allow the user to take a picture with the camera. However, once the user has taken a picture and they see the resulting image the first time through, they are allowed to tap on the ‘info’ button that exists on the first UIViewController instance. Once tapped, the ‘main’ UIViewController removes the existing UIViewController’s view and replaces it with the one for the info screen. The info screen has a ‘back’ button to switch the views back. However, once the user leaves the info screen and chooses to take another picture with the camera, the memory allocated to the info screen is still in memory.

The UIImagePickerController class temporarily uses almost 15-18MB while it processes the 2 megapixel image before releasing its internal references and the ‘imagePickerController:didFinishPickingImage’ delegate is called. I am running into low memory alerts once the second UIViewController instance has been created via the info button and then the user chooses to take another picture.

Memory technically is not leaking whether you take pictures over and over with or without tapping on the info button in my case, but due to other issues regarding background processes on the iPhone (Safari, etc.) that are beyond your control, you MUST free up as much memory as possible while working with things like the camera.

Any advice on how to cleanly create and destroy instances of the UIViewController class such that memory does not leak?

  • 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. 2026-05-11T09:36:58+00:00Added an answer on May 11, 2026 at 9:36 am

    Are you loading the second view controller from a NIB? If so, you’ll want to check that you’re releasing the associated memory correctly.

    Here’s what a typical NIB-based view controller looks like in my projects.

    SomeViewController.h

    @interface SomeViewController : UIViewController {     UILabel *someLabel; }  @property (nonatomic, retain) IBOutlet UILabel *someLabel;  @end 

    SomeViewController.m

    @implementation SomeViewController  @synthesize someLabel;  - (void)dealloc {     // Release our retained IBOutlets     self.someLabel = nil;     [super dealloc]; }  @end 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that Visual Studio under debugging options will fill memory with a known
I am having a similar issue to this person . The primary difference being
I'm creating a UIView similar to Apple's Scrolling example and I have a question
Assuming I am really pressed for memory and want a smaller range (similar to
I've seen many question regarding the malloc memory consumption, but none of them regarding
I am trying to work out some memory leak issues in an application, and
What would be a good way to detect a C++ memory leak in an
Buffer overrun problems are well known. Thus we were blessed with standard library functions
I have to take memory dump of IIS process for investigating an issue via
I have two computers. Both running WinXP SP2 (I don't really know ho similar

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.