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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:23:56+00:00 2026-05-31T00:23:56+00:00

Background – I am using automatic reference counting on a project. The root view

  • 0

Background –

I am using automatic reference counting on a project. The root view is a Table View (Master / Detail setup) showing a list of “slide shows”. Click on a table cell and you are taken to the detail view which consists of a Scroll view with views (viewController.view) in it (this is the “slide show”). Each slide show has a front cover and back cover (same view controller formatted differently) that sandwich an variable number of pages. Here is the code to load the slide show:

- (void)loadScrollView
{    
// The front and back cover are set in Interface Builder because they
// are reused for every slide show, just labels are changed.
[self.scrollView addSubview:self.frontCoverViewController.view];
[self.frontCoverViewController setCoverTitle:_data.name creationDate:_data.creationDate isFrontCover:YES];
[self.pagesArray addObject:self.frontCoverViewController];

for (int i = 0; i < [self getTotalNumberOfComps]; i++) 
{
    PageViewController *pageView = [[PageViewController alloc] init];
    pageView.data = [_compsArray objectAtIndex:i];

    [_scrollView addSubview:pageView.view];
    pageView.data.imgView = pageView.imageView;
    pageView.slideShowViewController = self;
    [_pagesArray addObject:pageView];
}

[self.scrollView addSubview:self.backCoverViewController.view];
[self.backCoverViewController setCoverTitle:_data.name creationDate:_data.creationDate isFrontCover:NO];
[self.pagesArray addObject:self.backCoverViewController];

[self.scrollView bringSubviewToFront:_frontCoverViewController.view];
[self setCurrentPage:0];
}

Problem –

So Im trying to reuse this slide show view controller so I need to nil and recreate the pages in the middle because each slide show has a different number of slides. Note a slide [PageViewController] is just a view with an ImageView in it. It has more functionality so we need the controller however the main display of the V.C. is the ImageView. I have created the following method to “empty” the slide show before running loadScrollView again with new data. Here is the empty method:

- (void)saflyEmptyScrollView
{
for (int i = 0; i < [self.pagesArray count]; i++) 
{
    if (i == 0 && i == ([self.pagesArray count]-1)) {
        CoverViewController *cover = (CoverViewController*)[self.pagesArray objectAtIndex:i];
        [cover.view removeFromSuperview]; 
    } else {
        PageViewController *page = (PageViewController*)[self.pagesArray objectAtIndex:i];
        [page.view removeFromSuperview];
        page = nil;
    }
}
self.pagesArray = nil;
self.pagesArray = [[NSMutableArray alloc] init];
} 

Big Question –

My main question is do I need to set the ImageView of each of these pages to nil? Or does setting the page itself to nil also free up the memory used by the ImageView/Labels/etc that are used in that view controller?

I tried adding self.imageView = nil; to the PageViewController’s viewDidUnload and viewWillUnload methods (one at a time not in both) and I realized that setting page = nil does not call the pages Unload methods. Am I freeing up memory correctly.

I’ve read a lot of articles but Im still not sure if Im managing memory in the best way possible. Thanks so much for the help!

  • 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-31T00:23:58+00:00Added an answer on May 31, 2026 at 12:23 am

    Generally, you shouldn’t have to set things to nil. And in this specific case, the setting things to nil is doing nothing.

    The line page = nil; is redundant, because the variable page goes out of scope immediately afterwards anyway. ARC knows this and doesn’t need you to set it to nil.

    And self.pagesArray = nil; is redundant because you follow it with self.pagesArray = [[NSMutableArray alloc] init];. The second line on its own will suffice.

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

Sidebar

Related Questions

Background I have a dimension table that has a single record for each day.
Background I have a ror application which is continuously recording and showing on a
Background: At my company we are developing a bunch applications that are using the
Background I am writing and using a very simple CGI-based (Perl) content management tool
Background This is only my second PyQt4 project. Developing a Windows app that has
Background My project is urgent and requires that I iterate a large XML file
Background Info setup: Rails 3 + Apache2 + Phusion Passenger 3.0.7 I deployed a
Background: I am using Eclipse to develop an Android app. I have an xml
Background Use Ajax to fire an event to the web server when a list
Background I've recently been a part of a project where twisted was used. We

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.