Android内存泄露中remove不掉是错的
Opened this issue · 2 comments
bbfxier commented
set.remove(p3); //此时remove不掉,造成内存泄漏
原文在这里https://github.com/francistao/LearningNotes/blob/master/Part1/Android/Android%E5%86%85%E5%AD%98%E6%B3%84%E6%BC%8F%E6%80%BB%E7%BB%93.md
samwangds commented
@Override
public int hashCode() {
return Objects.hash(name, pwd, age);
}
Person类重写了hashCode方法的话会重现。因为HashSet会根据气hashCode来判断是提取set中的元素。而这个值是add时候的值,在p3的成员变量改变后hashCode就变了.
ChenZeFengHi commented
正常情况下 修改对象内部变量 不会改变hashCode啊 所以也不会remove不掉啊