Article View: borland.public.csharpbuilder.language.csharp
Article #234Re: Where to cleanup an object instance
From: Joanna Carter [TeamB]
Date: Thu, 27 Jul 2006 08:38
Date: Thu, 27 Jul 2006 08:38
31 lines
2217 bytes
2217 bytes
"Francois PIETTE [ICS - MidWare]" <francois.piette@overbyte.be> a οΏ½crit dans le message de news: 44c66807@newsgroups.borland.com... | I'm porting Delphi code to C#. | In a Delphi class, you cleanup a class instance from the destructor. But in | C#, there is no destructor. | So where do I put cleanup code (such as closing database connection) ? | Should I put the cleanup code in Finalize() ? | Can I explicitely call Finalize() when I'm done with an object ? | I don't want the cleanup code to be called when the object instance is | garbage collected. I want it to be executed when I'm done with the object | instance. | | Maybe a better design is to create my Cleanup() method and call it from | where I used to call Delphi's destructor ? Unless you are using classes that implement IDisposable, those which hold Windows resources like file or UI handles, etc, you don't need to do any cleanup. In fact doing cleanup really fouls up the garbage collection and can slow your program due to memory fragmentation. If your code doesn't use Windows resources and you think deterministic cleanup is important, then you need to thnk about redesigning to work with, not against the GC. Joanna -- Joanna Carter [TeamB] Consultant Software Engineer
Technical Details
Message-ID:
<44c87b94@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshub.sdsu.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<44c66807@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 1efe35,57d58bae5e2b1da0 X-Google-Attributes: gid1efe35,public X-Google-Language: ENGLISH,ASCII From: "Joanna Carter [TeamB]" <joanna@not.for.spam> Newsgroups: borland.public.csharpbuilder.language.csharp References: <44c66807@newsgroups.borland.com> Subject: Re: Where to cleanup an object instance Date: Thu, 27 Jul 2006 09:38:30 +0100 Lines: 33 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 NNTP-Posting-Host: 83.70.200.69 Message-ID: <44c87b94@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1153989524 83.70.200.69 (27 Jul 2006 01:38:44 -0700) X-Authenticated-User: jcarter Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshub.sdsu.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail