Cook Computing

Deterministic Finalization

May 6, 2003 Written by Charles Cook

Sam Gentile's entry on an article in the June edition of MSDN Magazine caught my eye because of its suggestion of a solution to the lack of deterministic finalization in .NET, this being one of the major drawbacks of writing managed code. As luck would have it, this issue is the first after my subscription to the magazine expired and the ariticle doesnt go online until next week. However Im sceptical about whether the DF issue can be solved, even with Managed C++. For example, smart pointers are of no use because destructors are called non-deterministically for managed types and so there is no way of knowing when a reference to a managed type has gone out of scope.

The lack of DF, while adding extra work around resource management, does not bother me unduly. My experience with large-scale C++ projects is that memory corruption is a much bigger long-term problem and we can avoid that completely if we stick to verifiable managed code (bye bye C++, though I remember reading that a future version of Managed C++ will be able to generate managed code, presumably allowing only a small subset of C++). Failure to release resources is detected fairly early on during system testing whereas memory corruption can lurk for a very long time before showing itself, usually at an important customer site.

One solution would be to add ref counting to the CLR. I wonder what happened to Chris Sells project to to add ref-counting to Rotor and to study the performance effects?