FROM : Pete Callaway
DATE : Sun May 04 14:36:58 2008
Hi,
I'm having a problem with the retain count of CALayers. It seems that
when changing geometry related properties, such as bounds or position,
the retain count is decremented. Below is a simple example that
exhibits the problem. In the example, if changeName is called, the
retain count of the layer isn't touched, but if changePosition is
called, the retain count is decremented so far that the overridden
dealloc method is called.
I can hide the problem by turning on garbage collection, but that's
cheating. Does anyone have any ideas as to what might be causing this?
Cheers,
Pete
------------------------------------------------------------------------
@interface TestController : NSObject {
IBOutlet NSView *view;
TestLayer *_testLayer;
}
- (IBAction)changePosition:(id)sender;
- (IBAction)changeName:(id)sender;
@end
------------------------------------------------------------------------
@implementation TestController
- (void)awakeFromNib
{
view.wantsLayer = YES;
_testLayer = [[TestLayer alloc] init];
_testLayer.name = @"layer1";
[view.layer addSublayer:_testLayer];
}
- (void)dealloc
{
[_testLayer release];
[super dealloc];
}
- (IBAction)changePosition:(id)sender
{
NSPoint newPosition = _testLayer.position;
newPosition.x += 10;
_testLayer.position = newPosition;
}
- (IBAction)changeName:(id)sender
{
_testLayer.name = [_testLayer.name stringByAppendingString:@"1"];
}
@end
------------------------------------------------------------------------
@interface TestLayer : CATextLayer {
}
@end
------------------------------------------------------------------------
@implementation TestLayer
- (void)dealloc
{
NSLog(@"TestLayer dealloc called");
[super dealloc];
}
@end
DATE : Sun May 04 14:36:58 2008
Hi,
I'm having a problem with the retain count of CALayers. It seems that
when changing geometry related properties, such as bounds or position,
the retain count is decremented. Below is a simple example that
exhibits the problem. In the example, if changeName is called, the
retain count of the layer isn't touched, but if changePosition is
called, the retain count is decremented so far that the overridden
dealloc method is called.
I can hide the problem by turning on garbage collection, but that's
cheating. Does anyone have any ideas as to what might be causing this?
Cheers,
Pete
------------------------------------------------------------------------
@interface TestController : NSObject {
IBOutlet NSView *view;
TestLayer *_testLayer;
}
- (IBAction)changePosition:(id)sender;
- (IBAction)changeName:(id)sender;
@end
------------------------------------------------------------------------
@implementation TestController
- (void)awakeFromNib
{
view.wantsLayer = YES;
_testLayer = [[TestLayer alloc] init];
_testLayer.name = @"layer1";
[view.layer addSublayer:_testLayer];
}
- (void)dealloc
{
[_testLayer release];
[super dealloc];
}
- (IBAction)changePosition:(id)sender
{
NSPoint newPosition = _testLayer.position;
newPosition.x += 10;
_testLayer.position = newPosition;
}
- (IBAction)changeName:(id)sender
{
_testLayer.name = [_testLayer.name stringByAppendingString:@"1"];
}
@end
------------------------------------------------------------------------
@interface TestLayer : CATextLayer {
}
@end
------------------------------------------------------------------------
@implementation TestLayer
- (void)dealloc
{
NSLog(@"TestLayer dealloc called");
[super dealloc];
}
@end
| Related mails | Author | Date |
|---|---|---|
| No related mails found. | ||






Cocoa mail archive

