How to test dealloc-related behavior with ARC enabled?

Hi,


given the following piece of code in an ARC enabled project code coverage tells me it wasn't tested at all.

- (void)dealloc
{
#if !OS_OBJECT_USE_OBJC
    if (_queue) dispatch_release(_queue);
#endif
    _queue = NULL;
}


Besides the !OS_OBJECT_USE_OBJC macro the unsetting of _queue is not covered either so I have no clue if my tidying would work in production.


How am I able to do a specific testing on this dealloc?

(Manually calling it violates both MMR guidelines and ARC implementation.)

You could always write code like this to force the dealloc to happen:

Object *testObject = [[Object alloc] init];
testObject = nil;

To quote from the documentation concerning dealloc in an ARC environment (with emphasis):

You should typically not manage scarce resources such as file descriptors, network connections, and buffers or caches in a dealloc method. In particular, you should not design classes so that dealloc will be invoked when you think it will be invoked. Invocation of dealloc might be delayed or sidestepped, either because of a bug or because of application tear-down.

If your code coverage test told you that dealloc wasn't called, you've now had first hand evidence of one of the situations in which dealloc can be delayed or sidestepped.

How to test dealloc-related behavior with ARC enabled?
 
 
Q