views:

222

answers:

1

Would the code bellow cause my code to leak? More specifically, am I responsible for releasing the newImage or the contents of mainPageLayer (which is a CALayer object)? I get a memory warning every 4th time that method is called, but cant figure out why...

I also can't figure out why mainPageLayer.contents = [newImage CGImage]; throws a warning that the argument I am passing is of an incompatible pointer time. The image shows up just fine inside the layer.

-(void)setPrimaryPage:(UIImage *)newImage {
 pImageSizeWidth = newImage.size.width;
 pImageSizeHeight = newImage.size.height;

 [mainPageLayer setFrame:CGRectMake(0, 0, pImageSizeWidth, pImageSizeHeight)];
 mainPageLayer.contents = [newImage CGImage];
}
A: 

the contents property is defined as follows:

@property(retain) id contents

which means that the CGImageRef from newImage is retained. Whether your code leaks isn't clear from your code: There's not enough context. It will only leak if newImage was retained upon calling your setPrimaryPage:.

Alfons