How is it possible (if it is) to implement shared_ptr without requiring polymorphic classes to have virtual destructor?

Yes, it is possible to implement shared_ptr that way. Boost does and the C++11 standard also requires this behaviour. As an added flexibility shared_ptr manages more than just a reference counter. A so-called deleter is usually put into the same memory block that also contains the reference counters. But the fun part is that the … Read more

GC.Collect() not collecting immediately?

Objects with finalizers cannot be collected within a single garbage collection procedure. Such objects are moved to f-reachable queue, and remain there until finalizers are called. Only after that they can be garbage-collected. Following code is better, but you should not rely on it anyway: GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); Also, throwing exceptions in finalizer seems too … Read more

Why, really, deleting an incomplete type is undefined behaviour?

To combine several answers and add my own, without a class definition the calling code doesn’t know: whether the class has a declared destructor, or if the default destructor is to be used, and if so whether the default destructor is trivial, whether the destructor is accessible to the calling code, what base classes exist … Read more

Ruby: Destructors?

@edgerunner’s solution almost worked. Basically, you cannot create a closure in place of the define_finalizer call since that captures the binding of the current self. In Ruby 1.8, it seems that you cannot use any proc object converted (using to_proc) from a method that is bound to self either. To make it work, you need … Read more