Garbage-collected structs vs garbage-collected classes

Sean Eskapp eatingstaples at
Sat Jan 22 17:27:18 PST 2011

When I was using a class to wrap SDL functions and structs, I would have a
problem that Derelict would unload before the garbage-collector cleaned up my
classes, resulting in errors when these classes destructed and tried to call
SDL functions in the process. However, the exact same code using structs to
wrap instead of classes does not produce these errors. For example, rather
than using
scope screen = new Screen(800, 600)
where Screen is a scope class, I'm using
auto screen = new Screen(800, 600)
where Screen is a struct. This also provides me the advantage of being able to
use delegates which use screen. Is there a reason for this?

More information about the Digitalmars-d-learn mailing list