我使用LeakCanary检查我的应用程序是否有内存泄漏,它报告的泄漏情况如下

public AutofitHelper setEnabled(boolean enabled) {
if (mEnabled != enabled) {
mEnabled = enabled;
if (enabled) {
mTextView.addTextChangedListener(mTextWatcher);
mTextView.addOnLayoutChangeListener(mOnLayoutChangeListener);
autofit();
} else {
android.util.Log.i("linlian","AutofitHelper.setEnabled()remove="+mTextView);
mTextView.removeTextChangedListener(mTextWatcher);
mTextView.removeOnLayoutChangeListener(mOnLayoutChangeListener);
mTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
}
}
return this;
}代码调用setEnable(true)为TextView添加addTextChangedListener,我已经将setEnable(false)添加到removeTextChangedListener中,但这还不够,还有一个静态TextLine.sCached引用,即如何释放sCashed。
下面是我在TextLine中找到的代码片段
static TextLine recycle(TextLine tl) {
tl.mText = null;
tl.mPaint = null;
tl.mDirections = null;
tl.mMetricAffectingSpanSpanSet.recycle();
tl.mCharacterStyleSpanSet.recycle();
tl.mReplacementSpanSpanSet.recycle();
synchronized(sCached) {
for (int i = 0; i < sCached.length; ++i) {
if (sCached[i] == null) {
sCached[i] = tl;
break;
}
}
}
return null;
}但是,如何正确地使用它来循环静态sCashed
发布于 2015-05-28 06:25:42
我找到了一个相关的话题文本视图上的Android内存泄漏
Utils.clearTextLineCache()也许是一个很好的解决方案。
https://stackoverflow.com/questions/30388139
复制相似问题