How to allocate and delegate; or how to keep GC and the static analyzer happy
How to allocate and delegate; or how to keep GC and the static analyzer happy
- Subject: How to allocate and delegate; or how to keep GC and the static analyzer happy
- From: Glen Low <email@hidden>
- Date: Fri, 9 Oct 2009 10:33:49 +0800
Hi All
I have several cases of the following pattern in my code:
- (void)start
{
[[Something alloc] initWithDelegate:self];
}
- (void)finishWithSomething:(Something*)something
{
[something release];
}
The intent of course is that the Something object calls back the
caller with finishWithSomething: and that does the cleanup. Several UI
classes can work this way e.g. -[UIActionSheet
initWithTitle:delegate:...].
However as I understand it, there are several problems with this
pattern:
1. The code is not GC friendly as between the end of start and the
beginning of finishWithSomething, there are no references to the
object, so it may be collected.
2. The static analyzer in Xcode 3.2 doesn't like the construction,
thinking that the object is leaking from the start method.
Of course I could keep a reference to the something object in a field
of the calling object, but I was hoping to avoid that -- the calling
object may invoke start multiple times before each finishWithSomething:.
Any suggestions?
Cheers, Glen Low
---
pixelglow software | simply brilliant stuff
www.pixelglow.com
aim: pixglen
twitter: pixelglow
_______________________________________________
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