> I'm curious. If a class is written with an empty finalizer is there any
> reason why the compiler could not 'optimize' this away?
Wel, you've specifically requested a subtly different set of semantics
- in particular, it's guaranteed that objects with finalizers on won't
be garbage collected until they've been through the finalization queue.
While it's hard to immediately envisage a use for that on its own, it's
possible. (There can be reasons to have empty static constructors, for
instance - something I wouldn't have imagined before coming across the
curious behaviour of beforefieldinit.)
Out of interest, are you the Emma I think you are? If so, give my
regards to Andy and the team...

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
emma_middlebrook@fastmail.fm - 30 Sep 2005 16:19 GMT
Jon wrote:
> > I'm curious. If a class is written with an empty finalizer is there any
> > reason why the compiler could not 'optimize' this away?
[quoted text clipped - 6 lines]
> instance - something I wouldn't have imagined before coming across the
> curious behaviour of beforefieldinit.)
I sort of see what you mean but I can't think of a reason. Those
semantics were added by mistake so they should be taken out!
> Out of interest, are you the Emma I think you are? If so, give my
> regards to Andy and the team...
No, you're thinking of the other one!
Cheers
Emma
Jon Skeet [C# MVP] - 30 Sep 2005 16:40 GMT
> > Wel, you've specifically requested a subtly different set of semantics
> > - in particular, it's guaranteed that objects with finalizers on won't
[quoted text clipped - 6 lines]
> I sort of see what you mean but I can't think of a reason. Those
> semantics were added by mistake so they should be taken out!
I suspect the best solution to this would be for the compiler to issue
a warning if it detects a completely empty finalizer block - that would
get you to fix the code rather than getting the compiler to ignore the
fact that you've got something in there which basically shouldn't be
there.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too