[swift-dev] [Discussion] New refcount representation

Brent Royal-Gordon brent at architechies.com
Wed Mar 16 16:41:43 CDT 2016


>> I take it the refcount field's pointer is itself considered a weak reference, so the weak refcount starts +1 like the unowned refcount does?
> 
> You need to do something to make sure the side allocation is not freed if the object is live with no weak references to it. Biasing the weak refcount might work. 
> 
> It might be more robust to do something else, though. Ideally an incorrect weak reference decrement would deliberately log an underflow error and halt, instead of quietly freeing the side allocation out from under a live object.

The backreference from the side allocation could be used to indicate the object's liveness. Require the object to null that pointer before it performs its weak release; then if the weak refcount goes to zero before the backreference is null, you've had an unbalanced release.

-- 
Brent Royal-Gordon
Architechies



More information about the swift-dev mailing list