-1

I created a class (assuming the Tree). Then I initialize an instance:

Tree a = new Tree()

Now I want to delete instance a and free memory allocated for it. How I can do? I hope you help me solve this problem. Thank you very much!

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Robotic Vn
  • 437
  • 2
  • 7
  • 20

2 Answers2

0

You should dereference the object.then automatically during garbage collection memory will be deallocated. Dereferenceing can be done by Tree a = null;

Vinay S Jain
  • 111
  • 1
  • 11
0

I think that assigning a null value to an instance of a class will empty it, deleting any memory for it. Previous code:

Tree a;
a = new Tree();

New code:

Tree a;
a = new Tree();
//Empty out Tree 'a'
a = null;