Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
IDisposable Mysteries
Message
From
13/04/2011 11:41:19
 
 
To
13/04/2011 11:20:52
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:
01507136
Views:
52
>To carry this on further, as I understand it....
>
>You only need to implement Idisposable if you're going outside managed code to do something. For example, making a database connection, working with COM, etc. Otherwise, the class will cleanup on the next garbage collection.
>
>>So the question as to why one should implement the Idisposable interface at all, is one needs it if one wants to use the "using" syntax. When you do that you get a class that cleans itself up just as nicely as ... a vfp class.
>>
>>From what I understand, without the "using" statements, the idisposable is decorative, errh, is need if one wants to conform to "official" standards. :)

Not decorative. If a class implements IDisposable it is an indication that users of that class should call it's Dispose() method - either directly or indirectly using 'using'.
As Craig pointed out Dispose() only needs to be implemented if the class uses unmanaged resources.
Implement IDisposable() on any classes that you write that fall into this category.
Always check whether a .NET or third-party class implements IDisposable() and, if so, call the Dispose() method when you're finished with it. (There are exceptions to this - sometimes a class (e.g. ADO.NET Connection) will expose a Close() method and using this is preferable)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform