[gclist] Destructor FAQ
boehm.PARC@xerox.com
boehm.PARC@xerox.com
Fri, 8 Mar 1996 15:27:02 PST
"If I understand you correctly, you are suggesting that the programmer
write a routine that scans weak pointers regularly; if a pointer is set to
nil, then a cleanup routine would be invoked for that object. At
program exit, the remaining cleanup routines would be called."
Sorry. I was too cryptic again. I would still use a finalization mechanism to
clean up objects that are dropped during execution. I think this can be a
comparatively clean mechanism. But in addition I would keep a list of all
objects absolutely requiring cleanup at termination. This list has to be
maintained in such a way that:
a) It doesn't prevent objects from being finalized, and
b) objects are removed as part of finalization.
I would then use something like atexit to register routines to walk these lists
at program exit. The code in the atexit registered routine has to be extremely
careful. Not only may referenced objects have been previously finalized, but
objects reference from global variables, etc. may have been finalized. And all
of these seem to be unavoidable. It's not really clear that you can do much
more here than execute OS calls to deallocate system resources, something which
should have been done by the OS to start with.
The good news is that nothing needs to be cluttered with calls to scanning
routines.
Hans
Standard disclaimer ...