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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:06:49+00:00 2026-05-29T05:06:49+00:00

I watched WWDC 2010 104 session about implementing tiling on UIScrollView and I tried

  • 0

I watched WWDC 2010 104 session about implementing tiling on UIScrollView and I tried to implement it with some changes,but i have problem with real memory – I add UIImageView as subview to UIScrollView and i even tried to remove super view immediately after adding – and i have not my real memory cleaned.At all.
May be there is a problem with autoreleasing?

- (void)tilePages 
{
    [scrollView setContentSize:CGSizeMake(scrollView.bounds.size.width * [images count], scrollView.bounds.size.height)]; 

    CGRect visibleBounds = scrollView.bounds;
    int firstNeededPageIndex = floorf(CGRectGetMinX(visibleBounds) / CGRectGetWidth(visibleBounds));
    int lastNeededPageIndex  = floorf((CGRectGetMaxX(visibleBounds)-1) / CGRectGetWidth(visibleBounds));
    firstNeededPageIndex = MAX(firstNeededPageIndex, 0);
    lastNeededPageIndex  = MIN(lastNeededPageIndex, ([images count] - 1));

    for (ImageScrollView *page in visiblePages) {
        if (page.index < firstNeededPageIndex || page.index > lastNeededPageIndex) {
            [recycledPages addObject:page];
            [page removeFromSuperview];
        }
    }

    [visiblePages minusSet:recycledPages];

    for (int index = firstNeededPageIndex; index <= lastNeededPageIndex; index++) {
        if (![self isDisplayingPageForIndex:index]) {
            ImageScrollView *page = [self dequeueRecycledPage];
            if (page == nil) {
                page = [[[ImageScrollView alloc] init] autorelease];

                [page setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];

                if (self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
                    [page setContentMode:UIViewContentModeScaleAspectFill];
                } 
                else {
                    [page setContentMode:UIViewContentModeScaleAspectFit];
                }
            }
            [self configurePage:page forIndex:index];

            [scrollView addSubview:page];

            [visiblePages addObject:page];
        }
    }    
}

- (ImageScrollView *)dequeueRecycledPage
{
    ImageScrollView *page = [recycledPages anyObject];
    if (page) {
        [[page retain] autorelease];
        [recycledPages removeObject:page];
    }
    return page;
}

- (BOOL)isDisplayingPageForIndex:(NSUInteger)index
{
    BOOL foundPage = NO;
    for (ImageScrollView *page in visiblePages) {
        if (page.index == index) {
            foundPage = YES;
            break;
        }
    }
    return foundPage;
}

- (void)configurePage:(ImageScrollView *)page forIndex:(NSUInteger)index
{
    page.index = index;
    page.frame = [self frameForPageAtIndex:index];
    [page displayImage:[self imageAtIndex:index]];
}

- (CGRect)frameForPagingScrollView 
{
    CGRect frame = scrollView.bounds;
    return frame;
}

- (CGRect)frameForPageAtIndex:(NSUInteger)index {
    CGRect pagingScrollViewFrame = [self frameForPagingScrollView];

    CGRect pageFrame = pagingScrollViewFrame;
    pageFrame.origin.x = (pagingScrollViewFrame.size.width * index);
    return pageFrame;
}

- (UIImage *)imageAtIndex:(NSUInteger)index {
    return [images objectAtIndex:index];   
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    self.scrollView = nil;
    self.textView = nil;
}

- (void)dealloc
{
     [super dealloc];
     [scrollView release];
     [images release];
     [recycledPages release];
     [visiblePages release];
}
  • 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-29T05:06:51+00:00Added an answer on May 29, 2026 at 5:06 am

    You have implemented the demo correctly apart from one part. Memory is supposed to be released at the line

    [visiblePages minusSet:recycledPages];
    

    But i can see that you are storing your images in an array. Your images are being retained by that array and are not getting released, and as such are taking up memory.

    The goal with this code is to lazily load the images as they are needed. You don’t post where you initialise the images array but from what you have it looks to be pre-populated with images.

    Instead you should store the image paths in the array (everything you have done with it so far will still work) and then change the following method:

    - (UIImage *)imageAtIndex:(NSUInteger)index {
        NSSting * imagePath = [images objectAtIndex:index];
        UIImage * image = [UIImage imageWithContentsOfFile:imagePath];
        return image;   
    }
    

    Or something to that effect. There may be more efficient ways of loading the image depending where the image is coming from but the above should stop the crashing.

    If your images then take a long time to load and are blocking your interface you can do a couple of things. You can offload the image loading to a background thread using GCD or you can continue to watch that WWDC video and implement a CATiledLayer for the hi res image and place that over a low res image. The image will appear to crisp up at a very quick speed.

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

Sidebar

Related Questions

I've watched the WWDC 2010 talks about adopting multitasking and I have started enabling
I have watched railscast http://railscasts.com/episodes/236-omniauth-part-2 And tried to implement the code, everything worked well
I have watched a lot of youtube videos about binary code, but I don't
I watched few videos/webcasts about Oslo but I still fail to see how it
I just watched a 2011 WWDC presentation on Implementing UIViewController Containment ( here's a
I have recently watched a video of Nicholas Zakas talk about high performace scripts.
I just watched a session of PDC09 about new features of Entity framework in
I recently watched the 'Network Apps for the iPhone OS' videos for WWDC 2010
I have watched the railscast on devise for some reason he pulled out the
I watched Apple's WWDC 2010 video on Advanced Memory Analysis with Instruments and from

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.