Tue, 02 Dec 2008 22:32:33 -0800, Walter Bright wrote: > John Reimer wrote: >> Is there a ClassInfo flag indicating no-gc-collection for extern(C++) >> interfaces too? > > No. The COM object is special because part of its interface is to do its > own memory management, that isn't true in general for C++ interfaces.
But what's the typical use case for extern(C++) objects ? I think it's something like this: extern(C++) class CppInterfaceClass { ... } extern(C++) CppInterfaceClass create() { return new CppInterfaceClass(...); } extern(C++) void destroy(CppInterfaceClass obj) { delete obj; } Here, there are no references left in D code to the created interface object and GC is free to collect it even though it's still being used from within C++ code. I'll have to manage a list of created interface object simply to keep them alive, getting another multi-threading headache, or add them as GC roots. I think it's better to assume manual memory management for extern(C++) objects.