<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'><div>Imho you should take this approach:</div><div><br></div><div><br>If you are only managing memory and file handles and socket handles,<br>or Win32 kernel handles (events/mutexes/semaphores/registry keys),<br>you should just rely on the kernel cleaning everything up when the process dies.</div><div><br></div><div><br>Doing everything peacemeal is just a waste of time.</div><div><br></div><div><br></div><div>Imagine that there is a null deref and you abruptly go away.</div><div>That shouldn't/doesn't leak either.</div><div>And attempting to cleanup in this path is dangerous.</div><div><br></div><div><br></div><div><br></div><div><br>In fact, any resource that you want to guaranteeably be cleaned up,<br>should be backed by the kernel.</div><div><br></div><div><br></div><div><br>If you are talking over the network to something, and you abruptly exit,<br>that network server will eventually notice a timeout and clean up anything<br>it has allocated on your behalf.</div><div><br></div><div><br></div><div>Now, on the other hand, if your .dll is gracefull unloaded and the process</div><div>is still running, that is another matter, and one I suspect we don't handle.</div><div>I'm not sure we really handle .dll/.sos in Modula-3 w/o the main executable being Modula-3.</div><div>That could use repair.</div><div>On Windows it is a matter of writing DllMain in m3core.</div><div>Likely something similar on the other systems. Heck, maybe just a C++ static with a constructor and destructor.</div><div>That is kinda the portable interface to DllMain(process attach) and whatever are the Unix analogs.</div><div>Seriously. Just as we have main optionally in C.</div><div><br></div><div><br></div><div>Agreed?</div><div><br></div><div><br></div><div>Thread notifications would also be nice. This is an area that hasn't evolved as well as process notification.</div><div><br> - Jay<br><br><br><br><br></div><div>> Date: Fri, 29 May 2015 21:13:38 +0200<br>> From: estellnb@elstel.org<br>> To: m3devel@elegosoft.com<br>> Subject: [M3devel] WeakRef.T does not clean all WeakRefs on prorgam exit<br>> <br>> Today I was writing an object oriented interface to some external <br>> library.<br>> As every object holds at least a reference to an embedded C-heap object I<br>> wanted to make use of WeakRefs to get an automatic cleanup for the<br>> embedded C-heap objects. However I had to notice that no cleanup occurs<br>> and that the reference can still be reconstructed from the WeakRef even<br>> after assigning NULL and running the garbage collector by calling two times<br>> RTCollectorSRC.StartCollection & FinishCollection in sequence. I have<br>> further tried to disable incremental and generational collection and to set<br>> the gcRatio to 100.0 as well as moving the RefAny into a subprocedure<br>> but all of it did not help either. There is only one Refany in my program<br>> and thus no cyclic dependency.<br>> Does anyone have a suggestion on how I could make the automatic<br>> cleanup work ready for testing it (appart from calling the cleanup proc<br>> directly)?<br>> From the past I know the WeakRef implementation of PM3 to some extent:<br>> there was no special cleanup on program exit. I believe on program exit<br>> all WeakRefs should be freed in order to let the operating system reclaim<br>> all resources. Under Linux that should work automatically though some<br>> resources like sockets may last long until they become available again.<br>> Other OSes like the eComstation can not reclaim all resources when it<br>> comes f.i. to shared memory.<br>> Anyone here who believes that special cleanup for WeakRefs should be<br>> done on program exit?<br>> <br>> ... and one more question about how to handle WeakRefs?<br>> Do I need to keep the WeakRef-record after installing the cleanup proc<br>> with WeakRef.FromRef(...)? - or may I simply discard it while the cleanup<br>> should still be done without it?<br>> <br>> <br>> <br></div> </div></body>
</html>