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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:00:45+00:00 2026-05-24T17:00:45+00:00

So I’m having problems releasing some view controllers. In essence the dealloc for the

  • 0

So I’m having problems releasing some view controllers.
In essence the dealloc for the PhotoPostViewController never seems to get called, so I can’t clear down the images contained within that are munching all the memory.

This is my UIViewController subclass, I can have up to 100 of these at any one time added as subviews to the main scroll view, the iPad gets tight for memory after that.

@interface PhotoPostViewController : UIViewController {
    IBOutlet UIImageView *backgroundImage;
    IBOutlet UIImageView *serviceImage;
}

Then in my main view class I have a method to create these views and add them to a scrollView. This method is typically called from a loop to create all the subviews I need.

- (void) addPost {
    PhotoPostViewController *postView = [[PhotoPostViewController alloc] initWithNibName:@"PhotoPostViewController" bundle:nil];
    [scrollView addSubview:[postView view]];
    [viewControllers addObject:postView];
} 

viewControllers is an NSMutableArray created in the main class init.
scrollView is a UIScrollView on my main view.

This all works fine, I know the limit of the memory usage on the iPad and keep within that at any given time, opening Popovers to give preview images and videos etc…
Doesn’t run out of memory until I try to refresh the screen.
The code to do this is:

- (IBAction)didPressRefresh:(id)sender {
    for(UIView *subview in [scrollView subviews]) {
        [subview removeFromSuperview];
    }
    for(UIViewController *c in viewControllers) {
        [c release];
    }
    [viewControllers removeAllObjects];
}

For the sake of simplicity I clear off all the subviews and try to release them before recreating the next set of subviews using the function above.
It removes them from the view, but runs out of memory adding the new set of view controllers. In my test cases the sets of view controllers are identical in content, so if it loads from clean first time, then it should load the second time and every other time after that if I release everything properly.

What actually happens is it crashes due to low memory when creating the second set of view controllers.

While debugging I’ve put breakpoints on the ‘viewDidUnload’ and ‘dealloc’ methods, but they never get hit.

It looks like the UIViewController itself is getting released, yet the UIImageViews within are not, clearly they’d usually get released by my code in the dealloc (or viewDidUnload) method.

So I’m confused.
Counting things it looks to me like the reference counts are fine. so how come the dealloc is not getting hit ?

Andi

  • 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-24T17:00:46+00:00Added an answer on May 24, 2026 at 5:00 pm

    You need to send the postView object the -release message after adding it to the viewControllers collection:

    - (void) addPost {
       PhotoPostViewController *postView = [[PhotoPostViewController alloc] initWithNibName:@"PhotoPostViewController" bundle:nil];
       [scrollView addSubview:[postView view]];
       [viewControllers addObject:postView];
       [postView release];
    } 
    

    The reason why you need to do this is because the collection sends the -retain message to all objects that are added to it, hence the memory leak and -dealloc not being hit.

    EDIT:

    Your -didPressRefresh: method should look like this:

    - (IBAction)didPressRefresh:(id)sender {
        [[scrollView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];     
        [viewControllers removeAllObjects];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have some data like this: 1 2 3 4 5 9 2 6
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker

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.