Proposal: ClassInfo hasFinalizer field

Steven Schveighoffer schveiguy at yahoo.com
Mon Jun 6 07:06:47 PDT 2011


On Sun, 05 Jun 2011 01:22:30 -0400, Robert Jacques <sandford at jhu.edu>  
wrote:

> On Sun, 05 Jun 2011 00:28:58 -0400, dsimcha <dsimcha at yahoo.com> wrote:
>
>> On 6/4/2011 11:45 PM, Walter Bright wrote:
>>>
>>> One issue is that if someone derives from a class and adds a finalizer.
>>
>> One issue I did forget, though, is that these "empty" finalizers do  
>> deallocate the object's monitor.  (For those not familiar with these  
>> details, D classes contain a hidden monitor field that is null  
>> initially.  When you do synchronized(someClass), the monitor is lazily  
>> initialized.)  I guess we could get around this by setting the finalize  
>> bit in the monitor initialization code rather than upfront, for classes  
>> that don't do any other finalization.  This would almost always be more  
>> efficient than the status quo since very few classes use monitors.
>
> They shouldn't. Monitors can be shared across objects.

The destruction actually calls object._d_monitordelete, which uses  
reference counting to ensure sanity.

-Steve


More information about the Digitalmars-d mailing list