Memory leaks in Java are not similar to C/C++ because of garbage collector of Java. Java's GC is able to remove all instances that are not referenced; however, if you forget to remove a reference to an instance it would cause memory leak. I got the meaning of this sentence but I do not know what it means by removing reference to an instance.
How to demonstrate keeping reference to an object and de-referencing it?
Take following code as an example :
public String ObjPage(){
...
List<MyObject> myObj = retrieveObjs();
return "SUCCESS";
}
public List<MyObject> retrieveObjs(){
List<MyObject> objs = new ArrayList();
....
return objs;
}
Does this code de-reference its instances?