typeid + toString = runtime error
Ali Çehreli
acehreli at yahoo.com
Sun Dec 30 14:21:31 PST 2012
On 12/30/2012 08:11 AM, Namespace wrote:
> As far as I know this is because a class destructor is not a finalizer.
Thanks. It is a good way of looking at this issue. Wikipedia describes
the differences as
"Unlike destructors, finalizers are usually not deterministic. A
destructor is run when the program explicitly frees an object. In
contrast, a finalizer is executed when the internal garbage collection
system frees the object. Depending on the garbage collection method
used, this may happen at an arbitrary moment after the object is freed,
possibly never."
(I will continue with the D terminology and call it a destructor.)
Since a class destructor can be executed at any random time, the
operations that are valid are very limited. Could someone provide a list
on what can be done and cannot be done. Andrej Mitrovic noted that
printf works but is that guaranteed, or just happens to work?
Here is my partial list:
* Do not access members of the object that are garbage collected
themselves. The reason is, those members may have already been finalized.
* Similary, do not access any garbage-collected object.
* (I learned this one in this thread; is this correct?) Do not rely on
the runtime, as it may have been shutdown already.
* What else?
Ali
More information about the Digitalmars-d-learn
mailing list