Unable to free unused CALayer memory when using multiple layers

I am using several CALayer in my application with great UIImage as content. Unfortunately, when I do not need a layer and an image, the memory is not freed.

The code I use to create the layer is:

UIImage *im = [UIImage imageNamed:@"image_1.jpg"];
CALayer * l = [CALayer layer];
[l setBounds:CGRectMake(0, 0, 1024, 768)];
[l setPosition:CGPointMake(512, 384)];
[l setAnchorPoint:CGPointMake(0.5, 0.5)];
[l setHidden:NO];
[l setContents:(id) im.CGImage];
[self.layer addSublayer:l]; // self is a subclass of UIView
[self.tmpArr addObject:l]; // self.tmpArr contains the layers I am using (one in this example)

The code I use to release the layer and its contents:

CALayer * l = [self.tmpArr objectAtIndex:i];
[l removeFromSuperlayer];
[l setHidden:YES];
[l setContents:nil];
[self.tmpArr removeAllObjects];

when I use the tool memory profiler, I see that the real memory increases when the layer is created, but does not decrease when it is freed. I cannot use release since I am using ARC. what am i doing wrong here?

Thank.

+3
source share
2 answers

UIImage imageNamed: , .

:

  • -[UIImage imageWithContentsOfFile:].
  • . , .
+6

. , , CGImageCreateWithImageInRect. - CGImageRef. , CGImageRelease, - , 3 4 - .

CGImageRef.

0

All Articles