how do I know specifically which classes need to be disposed?
In short the
GC in Windows, some may argue
.NetFx, will handle the management of resources and its life-span on the system. In short, you don't have to worry about managing it in
.Net like you do in the unmanaged sphere (C, C++, etc.)
In general, objects that implement
IDisposable have the propensity to consume large quantities of resources (CPU, RAM, HDD, etc). Therefore, the developer decided to extend the
IDisposable interface to manually provide the logic to get rid of those resource hogs.
As a point of clarification, the
using statement is more of a syntactical sugar keyword for
try...finally. There are more guts and glory behind the logic of the
using statement but it all boils down to
try..finally; as a word of full-disclosure,
using statement does not implement
catch, that is all on you for that.
Is there a general rule of thumb or do you inspect class definitions to see if they somehow handle unmanaged resources?
Again, any "object" created inherits by default
Object. This is how .Net effectively becomes a managed utility. Even if you don't define an explicit inheritance to
Object, the compiler makes it inherit
The only resources you need to be concerned with are 3rd Party unverified libraries (DLL). If you try to attach it to a .Net project, it will scream "bloody murder" at you until you fix it properly.