D-Programming-Language/druntime — pull request #344 by denis-sh (2012-11-05 20:10:18+00:00)
Title: Fix `object.destroy` problem

We have a big problem with `object.destroy`.

#### Small problems first

When it first brought templates in druntime (`_isStaticArray`) someone could noticed that it's inconsistent and runtime library isn't a place for template code.

Then it became clear that `destroy` is broken for static arrays but nobody cares and leave such unpleasant situation with our core `object` module.

So my first commit fixes `destroy` to work properly and consistently with other runtime.

### Now the worst thing with `object.destroy`

Current situation with `destroy` is very dangerous as its behavior is inconsistent for different arguments:
* destroy on a class instance finalizes class instance, i.e. entity referenced by its parameter
* destroy on a pointer to struct destroys pointer by assigning it a `null` (it's common to expect it will destroy a struct itself)
* destroy on a struct destroys struct, i.e. parameter itself (but not any classes referenced by its fields)
* destroy on a static array destroys every element (but, again, not anything referenced by it)
* destroy on a dynamic array just assigns `null` to array variable

Even worse this behavior is undocumented and it never worked correctly for static arrays.

So my second commit supersedes `destroy` with `finalizeClassInstance` which is what should be in runtime. Probably it can be also/instead represented by `TypeInfo_{Class/Interface}.finalize` static member function.