Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android内存泄露中remove不掉是错的 #100

Open
bbfxier opened this issue Mar 28, 2018 · 2 comments
Open

Android内存泄露中remove不掉是错的 #100

bbfxier opened this issue Mar 28, 2018 · 2 comments

Comments

@bbfxier
Copy link

bbfxier commented Mar 28, 2018

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
Copy link

samwangds commented Apr 24, 2018

@bbfxier

        @Override
        public int hashCode() {
            return Objects.hash(name, pwd, age);
        }

Person类重写了hashCode方法的话会重现。因为HashSet会根据气hashCode来判断是提取set中的元素。而这个值是add时候的值,在p3的成员变量改变后hashCode就变了.

@ChenZeFengHi
Copy link

正常情况下 修改对象内部变量 不会改变hashCode啊 所以也不会remove不掉啊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants