JavaMemoryLeak public class JavaMemoryLeak {public static void main(String[] args) {People p1 = new People("libai", 11);People p2 = new People("dufu", 22);People p3 = new People("qingzhao", 33);HashSet set = new HashSet (); set.add(p1); set
public class JavaMemoryLeak { public static void main(String[] args) { People p1 = new People("libai", 11); People p2 = new People("dufu", 22); People p3 = new People("qingzhao", 33); HashSetset = new HashSet (); set.add(p1); set.add(p2); set.add(p3); System.out.println(set.size()); p3.setAge(999); //set.add(p3); set.remove(p3); System.out.println(set.size()); } } class People { private String name; private int age; public People(String name, int age) { this.name = name; this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } @Override public int hashCode() { return (this.name + this.age).hashCode(); } }