Destroying an instance

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 this I am doing the following:

meuObjeto = null;

The problem is that this code is only set to null the variable meuObjeto . In the rest of the system, the object still exists. How do I update all references in just one point of the code?

    
asked by anonymous 27.10.2015 / 01:05

1 answer

5

C # is a memory-managed language. So you do not destroy the object. It will be destroyed when there is no reference to it and the memory needs its space. gargabe collector will take care of this.

It is unnecessary to place null on the object. If the object is not being destroyed it is because there are references to it.

Then you just need to stop using the object. Probably the code is holding it unduly. I would have to analyze the code to find out where the error is.

    
27.10.2015 / 01:38