I am trying to understand the various causes of a memory leak with one of the patterns that I saw where hashCode () was implemented, not equals (). I read that if someone moves, the other should also be forwarded due to breach of contract.
this is sample code
import java.util.HashMap; import java.util.Map; public class MemoryLeak { static class Key { Integer id; Key(Integer id) { this.id = id; } @Override public int hashCode() { return id.hashCode(); } } public static void main(String[] args) {
I know that I did not use the equals () method specifically. But I want to understand why a memory leak occurs, what happens inside.
thanks
source share