Re: Is this pattern OK?

Tech-Archive recommends: Speed Up your PC by fixing your registry



Ben Voigt [C++ MVP] <rbv@xxxxxxxxxxxxx> wrote:

<snip>

What you ought to do instead is convert try / finally { Dispose(); } into
using blocks, which automatically handle the null case.

They also cope with the possibility of Dispose calls throwing
exceptions - with a single finally block, if an early Dispose call
fails, the rest won't get executed.

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
.



Relevant Pages

  • Re: Is this pattern OK?
    ... They also cope with the possibility of Dispose calls throwing ... exceptions - with a single finally block, ... World class .NET training in the UK:http://iterativetraining.co.uk ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Java memory leak
    ... > I would check that dispose is used any time you close a frame you ... FWIG there are actually true memory leaks when a frame has been closed ...
    (comp.lang.java.help)
  • Re: Paradigm for multiple IDisposables
    ... you and call IDisposable in the face of exceptions. ... IDisposable on MultiDispose, you have to wrap the call to Dispose on each ... a list of IDisposables inside the using statement, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Whats finally keyword good for?
    ... I write code for BLL and DAL, and I don't write the kind of code you are talking about that needs to be looking at a bunch of exceptions. ... databse server like Oracle and it blows with the connection open. ... One has a SQL command abort inside the USING with a open connection and no *close* and *dispose* occurs, and the connection is left open. ... // Open resources required for the processing ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Using XmlTextWriter without closing the base stream
    ... I feel ownership for (in particular if I explicitely ... then my instinct tells me that I should dispose of that object. ...
    (microsoft.public.dotnet.languages.csharp)