[MLton-user] Does GC always trigger MLtonFinalizable?

Matthew Fluet fluet at tti-c.org
Sun Feb 18 06:35:47 PST 2007


Tom Murphy wrote:
> Out of curiosity, when the program ends, how can there be any live data 
> at all? Are globals still considered live?

Well, technically, this function to run finalizers to quiescence is 
registered as an atExit function, so it runs when the program is 
preparing to end.  At this point, the closures of all atExit functions 
are still live, since they still need to be run; and, since code could 
still be run, all of the globals must kept live.  Included in the 
globals is the signal handler thread, which keeps the finalizer function 
closures alive, which is what we want, because the finalizers need to run.

> Matthew Fluet wrote:
>>
>>> So, my original question again: does a GC collect promise to run all 
>>> finalizers for all unreferenced objects?
>>
>> Sort of.  The code promises to run the finalizers for all objects that 
>> were determined to be unreferenced during the GC.  However, if some 
>> additional objects become unreferenced as a consequence of running the 
>> finalizers (say, because an object being finalized this round is 
>> holding the last reference to another finalized object), then their 
>> finalizers won't run until the next garbage collection.
>>
>> At program exit, we do run finalizers to quiescence, by repeatedly 
>> invoking the garbage collector.  Since the program is about to exit, 
>> there can't be too much live data around, so these collections should 
>> be fast, and quiescence should be reached quickly.
>>
>>
>>
>> _______________________________________________
>> MLton-user mailing list
>> MLton-user at mlton.org
>> http://mlton.org/mailman/listinfo/mlton-user
>>
> 
> _______________________________________________
> MLton-user mailing list
> MLton-user at mlton.org
> http://mlton.org/mailman/listinfo/mlton-user
> 
> 
> 




More information about the MLton-user mailing list