Free an Object

  • Thread starter Thread starter José Pérez Hernández
  • Start date Start date
J

José Pérez Hernández

Hi

How i can force to free an object in C# ?

Regards, and thanks in advance.
 
You cannot... all you can do is release all references to it and hope the
garbage collector will delete it as soon as possible. You can force a
garbage collect, but even then it's not guaranteed to delete it.

If you're concerned because the object holds on to resources and you want
them freed ASAP, then use the Dispose pattern. Have the object implement
IDisposable, having the Dispose method free the resources, and invoke
Dispose manually when you are done with the object.
 
Back
Top