Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
IDisposable Mysteries
Message
De
13/04/2011 11:41:19
 
 
À
13/04/2011 11:20:52
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 8.0
OS:
Vista
Network:
Windows XP
Database:
Jet/Access Engine
Application:
Desktop
Divers
Thread ID:
01506168
Message ID:
01507136
Vues:
53
>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)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform