3
How do I destroy an instance?
I have an object whose instance is referenced in various parts of my code. At some point I need to delete this object and for that I am doing the following:
meuObjeto = null;
The problem is that that code is only setando as null
the variable meuObjeto
. At the other points of the system, the object still exists. How do I update all references in only one point of the code?
I’m not sure it would be possible to do something like that. While some variable is pointing to a particular object it will not be "clean" by Garbage Collector, maybe if you made it implement the interface
IDisposable
, but it’s hard to say if something like that would be really right for your case without coming the code as a whole.– Christian Beregula
What you need is
System.GC.SupressFinalize(Objeto)
.– CypherPotato