[cfe-dev] Missing dealloc analysis

Ted Kremenek kremenek at apple.com
Thu Jul 3 09:05:58 PDT 2008

On Jul 3, 2008, at 12:55 AM, Jean-Daniel Dupas wrote:

> Le 3 juil. 08 à 07:35, Nikita Zhuk a écrit :
>> I noticed the addition of missing dealloc analysis in r53075. It's a
>> good idea to check that dealloc is implemented and that it always
>> calls [super dealloc], but there're couple of points I would like to
>> mention:
>> 1. It should be disabled in GC environment, because dealloc methods
>> are not called under GC
>> 2. In non-GC environment, the primary function of dealloc method is  
>> to
>> update retain counts of variables the object being dealloced is
>> pointing to. So that usually means that dealloc must be implemented
>> when an object has some ivars. Dealloc is not always required, and
>> there're lot of classes which don't need it (e.g. singleton classes).
>> Currently missing dealloc analysis requires every class to implement
>> dealloc and it's causing a lot of false positives.
>> I'm not completely sure if absence of ivars should be the only factor
>> which disables missing dealloc analysis, but at least in my case it
>> would suppress a lot of false positives.
> dealloc is also used to nullify the pointer in some other class that  
> have a weak reference on the disposed instance.
> You can have an object without ivar that is declare delegate of an  
> other object and should call -[setDelegate:nil] on dealloc.
> You have the same issue with notification listeners, that have to  
> unregister when they are disposed.
> And so, defining if dealloc should be implemented or not is not an  
> easy task.

I'd love to replicate some of these great observations in the check  
itself.  I'm not a Cocoa programmer, so if anyone would be kind to  
provide some self-contained code examples (that we can potentially add  
to the Clang testsuite) that would be awesome.

The goal of the check is to be pragmatic, not perfect.  Ideally the  
check will have a modest false positive rate at the risk of some false  
negatives.  If the check isn't useful than nobody will pay attention  
to it.

More information about the cfe-dev mailing list