[M3devel] WeakRef.T does not clean all WeakRefs on prorgam exit

Elmar Stellnberger estellnb at elstel.org
Fri May 29 21:00:44 CEST 2015


   Today I was writing an object oriented interface to some external 
library.
As every object holds at least a reference to an embedded C-heap object I
wanted to make use of WeakRefs to get an automatic cleanup for the
embedded C-heap objects. However I had to notice that no cleanup occurs
and that the reference can still be reconstructed from the WeakRef even
after assigning NULL and running the garbage collector by calling two times
RTCollectorSRC.StartCollection & FinishCollection in sequence. I have
further tried to disable incremental and generational collection and to set
the gcRatio to 100.0 as well as moving the RefAny into a subprocedure
but all of it did not help either. There is only one Refany in my program
and thus no cyclic dependency.
   Does anyone have a suggestion on how I could make the automatic
cleanup work ready for testing it (appart from calling the cleanup proc
directly)?
   From the past I  know the WeakRef implementation of PM3 to some extent:
there was no special cleanup on program exit. I believe on program exit
all WeakRefs should be freed in order to let the operating system reclaim
all resources. Under Linux that should work automatically though some
resources like sockets may last long until they become available again.
Other OSes like the eComstation can not reclaim all resources when it
comes f.i. to shared memory.
   Anyone here who believes that special cleanup for WeakRefs should be
done on program exit?

   ... and one more question about how to handle WeakRefs?
Do I need to keep the WeakRef-record after installing the cleanup proc
with WeakRef.FromRef(...)? - or may I simply discard it while the cleanup
should still be done without it?






More information about the M3devel mailing list