Documentation of object.destroy

Temtaime temtaime at gmail.com
Tue Jan 2 14:22:06 UTC 2018


On Tuesday, 2 January 2018 at 13:58:49 UTC, Johan Engelen wrote:
> Hi all,
>
> Link: https://dlang.org/library/object/destroy.html
>
> The documentation says "Destroys the given object and puts it 
> in an invalid state. " However, this is not (strictly) true. 
> What destroy() does is overwrite the object with T.init (or 
> zeros), and we should explicitly mention that. Also, the 
> documentation states "that it [the object destroyed] no longer 
> references any other objects.", which is wrong as this code 
> shows:
>
> ```
> __gshared int global;
> struct S {
>     int* pint = &global;
> }
> void main() {
>     S s;
>     int i;
>     s.pint = &i;
>     assert(s.pint != &global);
>     destroy(s);
>     assert(s.pint != &global); // fails
> }
> ```
> https://run.dlang.io/is/SFbxNm
>
> How about:
> "Destroys the given object `obj` and puts `obj` in its `T.init` 
> state. This function used to destroy an object such that any 
> cleanup by the destructor or finalizer is done, and such that 
> `obj` no longer references any other objects (unless `T.init` 
> references other objects). This function does not initiate a GC 
> cycle nor free any GC memory."
>
> regards,
>   Johan

Why not zerofy the object ?


More information about the Digitalmars-d mailing list