未处理的内存泄漏的可能性 [英] Possibility of unhandled memory leak

查看:163
本文介绍了未处理的内存泄漏的可能性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我来自iOS的环境,所以这就是为什么这个问题会很明显。

First of all, I come from iOS environment, so this is why this question might be obvious.

我知道Android有垃圾收集器,但是仍然对象引用(保留)等对象,我的理解是GC只会删除的对象,如果它没有引用(可能是我错了,在这点)。望着这code:

I know Android has Garbage Collector, but objects still reference (retain) other objects, and my understanding is the GC will only remove an object if it has no references (probably I'm wrong in this point). Looking at this code:

private void addDefaultTextWatcher(final EditText editText) {
        editText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                value = s.toString();
                if (getOnValidate() != null) {
                    getOnValidate().validate(editText, s.toString());
                }
            }
        });
    }

EDITTEXT 具有参考 TextWatcher 匿名类,这个类有 EDITTEXT 为好。垃圾收集器要照顾这对我?如果没有...什么建议的方法?

editTexthas a reference the TextWatcher anonymous class, and that class has a reference to editText as well. Is Garbage collector going to take care of this for me? If no... what is the suggested approach?

推荐答案

Java垃圾收集器是足够聪明的认识循环引用。你应该什么都不做。

Java Garbage Collector is smart enough to recognize cycle references. You should do nothing.

这篇关于未处理的内存泄漏的可能性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆