Why is GC.collect not @safe?
Steven Schveighoffer
schveiguy at gmail.com
Wed Aug 2 13:27:50 UTC 2023
On 8/2/23 7:40 AM, Nick Treleaven wrote:
> Presumably an allocation like `new T` (for a type with a @safe
> constructor) can be made anywhere a call to `GC.collect` can be made,
> which may trigger a collection. So why isn't `GC.collect` marked @safe?
It should be. Maybe historical reasons?
One possible (but wrong) reason is that destructors can be unsafe. But
you are correct in that allocation can cause a collection.
-Steve
More information about the Digitalmars-d-learn
mailing list