http://wiki.dlang.org/DIP68

This DIP proposes the addition of a compiler-enforced @nogc attribute on types. This means means such a type cannot be allocated by the GC, e.g., using operator new on such a type or appending such a type to a dynamic array, would result in compile-time errors.

It enforces separation between deterministic and non-deterministic finalization and lifetime of objects, which is crucial for proper RAII idiom.

For instance, suppose you require deterministic finalization of some resource, which is encapsulated by a struct whose destructor *must* be called. If your users could (accidentally?) create this object in the GC heap (e.g, holding it in an AA), you lose all RAII guarantees and break the code's assumptions.


-tomer

Reply via email to