Added CAGradientLayer, getting this in my UIView dealloc: [CALayer release]: message sent to deallocated instance
- by developerdoug
Here there,
I have a custom UIView. This view acts as a activity indicator but as label above the UIActivityIndicatorView. In the init, I add a CAGradientLayer. I allocate and initialize it and insert it at index 0 as a sublayer of the UIView layer property. In my dealloc method was called, I received a message in the console:
- [CALayer release]: message sent to deallocated instance.
My code:
@interface LabelActivityIndicatorView ()
{
UILabel *_label;
UIActivityIndicatorView *_activityIndicatorView;
CAGradientLayer *_gradientLayer;
}
@end
@implementation LabelActivityIndicatorView
//dealloc
- (void) dealloc
{
[_label release];
[_activityIndicatorView release];
//even tried to remove the layer
[_gradientLayer removeFromSuperLayer];
[_gradientLayer release];
[super dealloc];
}
// init
- (id) initWithFrame:(CGRect)frame
{
if ( (self = [super initWithFrame:frame]) )
{
// init the label
// init the gradient layer
_gradientLayer = [[CAGradientLayer alloc] init];
[_gradientLayer setBounds:[self bounds]];
[_gradientLayer setPosition:CGPointMake(frame.size.width/2, frame.size.height/2)];
[[self layer] insertSublayer:_gradientLayer atIndex:0];
[[self layer] setNeedsDisplay];
}
return self;
}
@end
Anyone have any ideas. Since I'm allocating and initializing the gradient layer I'm responsible for releasing it. I should be able to alloc and init and assign to some ivar. Perhaps I should create a property with retain on it.
Thanks,