• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
How to allocate and delegate; or how to keep GC and the static analyzer happy
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: How to allocate and delegate; or how to keep GC and the static analyzer happy
      • From: Jens Alfke <email@hidden>
  • Prev by Date: Automatic language detection - a bug (again) or what. Snow Foundation NSSpellServer.
  • Next by Date: Re: Hide an Item on Desktop
  • Previous by thread: [moderator] Re: Software visualisation tool
  • Next by thread: Re: How to allocate and delegate; or how to keep GC and the static analyzer happy
  • Index(es):
    • Date
    • Thread