title: IOS Core Animation objects are not releasing
body: <p>I am making an image gallery application in IOS where user can browse the gallery images. I used a paging enabled <code>UIScrollView</code> like in <a href="https://developer.apple.com/library/ios/samplecode/PageControl/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007795">this</a> 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.</p>
  
  <hr>
  
  <pre><code>|Graph---|Category------------------|Live Bytes---|#Living----|#Transient
  
  |1-------|All Heap &amp; 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
  </code></pre>
  
  <hr>
  
  <p>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 <code>View Controller</code></p>
  
  <p>I tried removing the animations from the layers using following method after each paging. but it does not work.</p>
  
  <pre><code> - (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 &gt; 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]];
  
          }
      }
  
  }
  </code></pre>
  
  <p>Please help me if anyone knows how to release those core animation objects.</p>