Re: UnitTest: object Should be Dealllocated
Re: UnitTest: object Should be Dealllocated
- Subject: Re: UnitTest: object Should be Dealllocated
- From: Andreas Grosam <email@hidden>
- Date: Wed, 26 Jun 2013 17:56:04 +0200
On 26.06.2013, at 16:55, Kyle Sluder <email@hidden> wrote:
> On Jun 26, 2013, at 6:15 AM, Andreas Grosam <email@hidden> wrote:
>
>> There is a class whose implementation may be prone to accidentally have a _strong_ reference elsewhere (namely within a block), which effectively prevents the object to be deallocated in certain scenarios when it should.
>>
>> When carefully implemented that doesn't happen, though.
>>
>>
>> How can I create a Unit Test which tests such cases, e.g.:
>>
>> Foo* foo;
>> @autoreleaspool {
>> foo = [Foo new];
>> [foo doSomething];
>> foo = nil; // should deallocate foo
>> }
>> ASSERT_DEALLOCATED_TRUE(foo);
>>
>>
>> Of course, the "doSomething" is more complicated involving possibly suspended dispatch queues and blocks, etc.
>
> Create a __weak reference to foo and assert that it is nil?
Yes that works! Thanks, Kyle!
>
> --Kyle Sluder
_______________________________________________
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