I am wondering if the following piece of code is a memory leak, since Google is only turning up weird examples. Basically, if I have a class Tree
:
public class Tree{
private Bird[] birds;
public Tree(){
birds = new Bird[100];
}
}
and I hold a class reference to a Tree
like this:
Tree myTree = new Tree();
and then shortly afterwards I set that reference to null
:
myTree = null;
Will all the 100 allocated Birds be taken care of WITH the tree class by the garbage collector? Or do I need a delete()
method? I know Java doesn't have destructors but still this multi-layer class example confuses me:
inside Tree.java
:
public void deleteBirds{
birds = null;
}