Thursday, February 5, 2009

CALayer leaks from UIButton

I don't know why, but I was leaking CALayer objects when I used the code:

UIButton *button = [[UIButton buttonWithType:UIButtonTypeCustom] initWithframe: myCGRect];

I solved this by replacing the above code with this:

UIButton *button = [[[UIButton alloc] initWithFrame:myCGRect] autorelease];

If you know why this is, I'd love to hear about it.

No comments:

Post a Comment