On Monday, 17 December 2012 at 22:08:08 UTC, Jeremy DeHaan wrote:
It's not the only way, but it's the easiest way.
What are some other ways? I am just curious.
You could use module destructors to cleanup at program exit and
use RAII via struct destructors for short-lived objects.
Also, if we were able to know the size of the object the
pointer is referring to, couldn't we then add it to the GC? It
sounds like a pretty complicated way, but wouldn't that be a
good way if it were possible?
No, that's a bad idea. What if the C library you are using
maintains some sort of internal bookkeeping related to the
pointer? What if it keeps a copy of the pointer internally? If
the GC collects your D-side pointer, how is the C library
supposed to know it's time to cleanup everything associated with
that pointer?