Isolated synchronous deinit

You gave one in your original post (emphasis mine):

Combination of automatics reference counting and deterministic deinitialization makes deinit in Swift a powerful tool for resource management.

There even exists a roadmap to make it more deterministic.

But deinitialization would become much less deterministic if a subclass can turn a nonisolated deinit into an isolated one. Code like the one below would become fragile:

open class MyClass { ... }

do {
    let instance = MyClass(...)
    ...
}
// <- Here some code that relies on a deinitialized instance

A subclass with an isolated deinit would break the above code, unless I'm mistaken.

Some people will tell that this code was fragile anyway, because who knows where instance could be retained? Well, the author of the code knows, and relies on deterministic deinitialization.

3 Likes