Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
IDisposable Mysteries
Message
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB 8.0
OS:
Vista
Network:
Windows XP
Database:
Jet/Access Engine
Application:
Desktop
Miscellaneous
Thread ID:
01506168
Message ID:
01506281
Views:
48
>Also, I think your implementation is a bit wonky :-{
>
>Absolutely. Thanks. I need to set the local (static) disposed to true. But if I do that, then my implementation is the equivalent to the "recommended" one, isn't it?

No. Don't use static - the value will be common to all instances of the class - it should be private at class level. The clean-up code I suggested can be called either by an explicit call to Dispose() from code or implicitly by the garbage collector when it calls the Finalize() method.
If it is called explicitly (as it should be) then there is no need for the GC to repeat the process.

>
>As a general rule if a class implements IDisposable the user should call it's Dispose() method when they have finished using it.
>
>So you're saying (assuming we don't use the "using" construct) that this is really kind of a communication device between the developer of the class and the programmer who uses it? What happened to the "read.me" files :)?

Yes. A class that implements IDisposable indicates to anything concerned that it should call Dispose(). This is, essentially, how the compiler translates the presence of a 'Using' block - if the created class implements IDisposable then it will automatically call Dispose() on that class at the end of the block.

>In the second case the user (and, as importantly, the framework Using statement) would not be aware that it was recommended. Resources would only be released when the GC got round to finalizing it.
>
>Your implementation explicitly calling the GC, There are those who would say that is blasphemous, no? :)

I think you are thinking of instigating a garbage collection (which is not usally a good idea). That's not what this code does - it just tells the garbage collector that there is not need for it to waste it's time calling Finalize() on the class instance since the Dispose() has already taken care of it.

>But thanks for caring and kind regards,
>
>Marc
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform