Basics about Java memory leak
===

I read that [Java is passed by value][1] . So lets say we have this code and say that the `HashMap somehashMap` has a longer life time than `foo` . So foo is not allowed to be garbage collected even though it has done its work simply because we put foo inside the Map and then forgot to remove from it  . Now going by the logic of the answer in the post that I linked to we are actually passing a copy of the reference of `foo` to the method `put()` right ?In that case putting the `foo` into the `HashMap` shouldn't prevent it from getting garbage collected . Can you please help me understand what is going on here ? What am I missing exactly ?

   

     public void someMethod(){
         Foo foo  = new Foo();
         somehashMap.put(fooKey,foo); 
      }
       

[1]:http://stackoverflow.com/questions/9224517/what-is-a-class-reference-and-an-object