deleting class objects
-
Hi, I want to delete a C# class object and all the resources used by the class before the garbage collector does it. How do I do it in C#. Thanks.
If the object represents a truly limited resource, it should implement
IDisposable and then one would call `object.Dispose()` when they are done with it. If it isn't a limited resource that needs active maintaince then let the system handle it by normal garbage collection.
-
Hi, I want to delete a C# class object and all the resources used by the class before the garbage collector does it. How do I do it in C#. Thanks.
You don't. If the class inherits IDisposable, e.g. has a Dispose method, you call that method to clean up any unmanaged resources. Then you get rid of the reference to the object, and it will be garbage collected eventually. You can invoke a garbage collection manually, but there is very rarely any reason to do so. If the system or the .NET heap needs more memory, a garbage collection will occur to try to free up memory. --- b { font-weight: normal; }