Re: CALayer - delegate not being called?
Re: CALayer - delegate not being called?
- Subject: Re: CALayer - delegate not being called?
- From: Paul Goracke <email@hidden>
- Date: Tue, 27 Nov 2007 23:02:18 -0800
stephen joseph butler wrote:
On Nov 28, 2007 12:12 AM, Paul Goracke <email@hidden> wrote:
BTW, this line scares me:
[layer setDelegate:[[[SimpleDelegate alloc] init] retain]];
You have the implicit retain from "init", then you're retaining
again,
then I assume the layer also retains it in setDelegate. Are you sure
you don't mean "autorelease" instead of "retain"?
I don't know much about CoreAnimation, but in the delegate model
delegates are typically *NOT* retained. Autorelease would be
inappropriate here. The best thing to do would be to store the
SimpleDelegate instance elsewhere and make sure to release it at the
end.
I'll go along with that; I didn't find specifics when I did a _very_
cursory search. Since I tend to use 'self' as a delegate, I rarely run
into the situation of whether to retain a delegate created solely for
that purpose. Maybe autorelease isn't appropriate, but is retain-
following-init ever necessary? As there seems to be no held reference
to the SimpleDelegate here, where would he call release since the
layer won't do it?
CALayer *layer = [CALayer layer];
This needs to be retained somewhere. Otherwise, it gets released after
the first run through the run loop (which would explain why your
delegate is never called!).
I believe "self.layer = main" is retaining it before it can get
autoreleased.
pg
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden