Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS Core Animation objects are not releasing

I am making an image gallery application in IOS where user can browse the gallery images. I used a paging enabled UIScrollView like in this sample code. Everything is working. But the problem is while I scroll through the pages, number of core animation objects are created and they never releases.


|Graph---|Category------------------|Live Bytes---|#Living----|#Transient

|1-------|All Heap & Anonymous VM   |58.69 MB-----|270335-----|828951   
|0-------|All Heap Allocations------|15.30 MB-----|269980-----|826939   
|0-------|All Anonymous VM----------|43.39 MB-----|355--------|2012     
|0-------|VM: CoreAnimation---------|27.01 MB-----|222--------|58  
|0-------|VM: CG image--------------|7.40 MB------|3----------|189      
|0-------|VM: UITextFieldLabel------|4.30 MB------|25---------|0

using instruments i observed that for each paging 4-6 objects are created. But they are not going to release even if I left the View Controller

I tried removing the animations from the layers using following method after each paging. but it does not work.

 - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{

CGFloat pageHeight = CGRectGetHeight(self.ImageSlider.frame);
NSUInteger page = floor((self.ImageSlider.contentOffset.y - pageHeight / 2) / pageHeight) + 1;
currentPage = page;
delegate.currentPage = page;
[delegate refreshTags];

[self unloadPageFromScrollView:currentPage-2];
[self unloadPageFromScrollView:currentPage+2];

[self loadScrollViewWithPage:currentPage - 1];
[self loadScrollViewWithPage:currentPage];
[self loadScrollViewWithPage:currentPage + 1];

}

- (void)unloadPageFromScrollView:(NSUInteger)page
{
    @autoreleasepool {
        if (page > docList.count-1) {
            return;
        }

    if ((NSNull *)[self.viewControllers objectAtIndex:page] != [NSNull null]) {
        PageViewController1 *controller = [self.viewControllers objectAtIndex:page];
        for (CALayer* layer in [self.view.layer sublayers]) {
                [layer removeAllAnimations];
        }
        [controller.view removeFromSuperview];

        [self.viewControllers replaceObjectAtIndex:page withObject:[NSNull null]];

        }
    }

}

Please help me if anyone knows how to release those core animation objects.

like image 764
krishantha Jayathilake Avatar asked Sep 26 '13 09:09

krishantha Jayathilake


1 Answers

Found out that animation caused by the inner pages.

Inside the pageViewController(viewController that added to the scrollView as a page) on viewWillDisappear:(BOOL)animated method I added this

    for (CALayer* layer in [self.view.layer sublayers])
    {
        [layer removeAllAnimations];
    }

it resolved the problem.

like image 159
krishantha Jayathilake Avatar answered Oct 17 '22 12:10

krishantha Jayathilake