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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:08:40+00:00 2026-05-11T18:08:40+00:00

I have some UIImageViews that are nested in UIViews, which group them together. They’re

  • 0

I have some UIImageViews that are nested in UIViews, which group them together. They’re owned by an view controller. As soon as the -viewWillDisappear method is called, I want to remove those UIImageViews with their UIViews alltogether, so that the memory gets freed up.

I call -release on the UIViews that contain the UIImageViews as subviews. Nothing else owns the UIImageViews. All I have is an instance variable to the UIView which groups the UIImageViews together.

So when I send -release to it, the retain count should become 0. But that’s not a guarantee that I get more free memory, right? So, I also set myUIView = nil. Is that helpful / useful? How do you free up memory safely?

  • 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-11T18:08:40+00:00Added an answer on May 11, 2026 at 6:08 pm

    The best thing to do in -viewDidDisappear (not -viewWillDisappear; you’re still onscreen at that point) for this case is to call self.view = nil. That will dump the entire view controller’s view, which will be automatically reloaded for you next time it’s needed.

    If you have any IBOutlets on those views, you need to set them to nil, too or they won’t release. Assuming you have a setup like this:

    @interface MyViewController : UIViewController
    {
       UIImageView *_imageView;
    }
    @property (readwrite, retain) IBOutlet UIImageView *imageView;
    
    @implementation MyViewController
    @synthesize imageView = _imageView;
    

    Then you need to call self.imageView = nil in your `-viewWillDisappear.

    You generally should not call -release on your ivars except in their accessors and in -dealloc. The correct way to release them is to set them to nil using an accessor.

    Caling -release when the retainCount is 1 will immediately call free(), which will recover memory. Remember, however, that other things may be retaining the object, including the autorelease pool, so you may not be certain what the retain count is at any given time.

    I strongly advise people when they release a variable to immediately set it to nil. This doesn’t impact the variable; it just protects you from chasing a pointer that you’ve released and so may now point to unallocated memory. So in -dealloc, I have lines that look like this:

    [_stuff release]; _stuff = nil;
    [_otherStuff release]; _otherStuff = nil;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some UIViews that have different centers and transforms applied to them. I
I have UIScrollView and number of objects (UIView compositions) with UIImageViews inside them. Some
I have several UIViews and UIImageViews that are loaded inside a UIScrollView. Each page,
I have a bunch of UIImageViews that are in different proportions. Some of 100x101
I have two UIImageViews that contain images with some transparent area. Is there any
I have a UIViewController that first sets up the view and initializes some HTTPRequests
I have some code that displays a checkmark as the auxiliary view of a
I have an app that will show some images using UIImageView, now I want
I have some arbitrary pixel data that I want to save as a PNG.
I have some text lines like that : vt_wildshade2^508^508 vt_ailleurs2^1188^1188 ... vt_high2^13652^13652 Is it

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.