Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / September 2005

Tip: Looking for answers? Try searching our database.

empty finalizer bad for performance?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
emma_middlebrook@fastmail.fm - 28 Sep 2005 14:52 GMT
Hi

I'm curious. If a class is written with an empty finalizer is there any
reason why the compiler could not 'optimize' this away?

Cheers

Emma Middlebrook
Jon Skeet [C# MVP] - 28 Sep 2005 15:25 GMT
> 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


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.