Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e5ea4403 authored by Romain Guy's avatar Romain Guy
Browse files

Plug memory leak in EditText.

Change-Id: I0b42c23ceeaa958d02255945c35ff6807c177114
parent 704972ac
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -274,8 +274,11 @@ extends Layout
            sStaticLayout = null;
        }

        if (reflowed == null)
        if (reflowed == null) {
            reflowed = new StaticLayout(true);
        } else {
            reflowed.prepare();
        }

        reflowed.generate(text, where, where + after,
                getPaint(), getWidth(), getAlignment(), getTextDirectionHeuristic(),
@@ -356,6 +359,7 @@ extends Layout

        synchronized (sLock) {
            sStaticLayout = reflowed;
            reflowed.finish();
        }
    }

@@ -485,7 +489,7 @@ extends Layout
    private int mTopPadding, mBottomPadding;

    private static StaticLayout sStaticLayout = new StaticLayout(true);
    private static Object sLock = new Object();
    private static final Object[] sLock = new Object[0];

    private static final int START = 0;
    private static final int DIR = START;
+21 −21
Original line number Diff line number Diff line
@@ -29,14 +29,15 @@ import com.android.internal.util.ArrayUtils;
 */
class MeasuredText {
    private static final boolean localLOGV = false;
    /* package */ CharSequence mText;
    /* package */ int mTextStart;
    /* package */ float[] mWidths;
    /* package */ char[] mChars;
    /* package */ byte[] mLevels;
    /* package */ int mDir;
    /* package */ boolean mEasy;
    /* package */ int mLen;
    CharSequence mText;
    int mTextStart;
    float[] mWidths;
    char[] mChars;
    byte[] mLevels;
    int mDir;
    boolean mEasy;
    int mLen;

    private int mPos;
    private TextPaint mWorkPaint;

@@ -44,16 +45,16 @@ class MeasuredText {
        mWorkPaint = new TextPaint();
    }

    private static MeasuredText[] cached = new MeasuredText[3];
    private static final Object[] sLock = new Object[0];
    private static MeasuredText[] sCached = new MeasuredText[3];

    /* package */
    static MeasuredText obtain() {
        MeasuredText mt;
        synchronized (cached) {
            for (int i = cached.length; --i >= 0;) {
                if (cached[i] != null) {
                    mt = cached[i];
                    cached[i] = null;
        synchronized (sLock) {
            for (int i = sCached.length; --i >= 0;) {
                if (sCached[i] != null) {
                    mt = sCached[i];
                    sCached[i] = null;
                    return mt;
                }
            }
@@ -65,14 +66,14 @@ class MeasuredText {
        return mt;
    }

    /* package */
    static MeasuredText recycle(MeasuredText mt) {
        mt.mText = null;
        if (mt.mLen < 1000) {
            synchronized(cached) {
                for (int i = 0; i < cached.length; ++i) {
                    if (cached[i] == null) {
                        cached[i] = mt;
            synchronized(sLock) {
                for (int i = 0; i < sCached.length; ++i) {
                    if (sCached[i] == null) {
                        sCached[i] = mt;
                        mt.mText = null;
                        break;
                    }
                }
@@ -84,7 +85,6 @@ class MeasuredText {
    /**
     * Analyzes text for bidirectional runs.  Allocates working buffers.
     */
    /* package */
    void setPara(CharSequence text, int start, int end, TextDirectionHeuristic textDir) {
        mText = text;
        mTextStart = start;
+8 −0
Original line number Diff line number Diff line
@@ -924,6 +924,14 @@ public class StaticLayout extends Layout {
        mMaximumVisibleLineCount = lineCount;
    }
    
    void prepare() {
        mMeasured = MeasuredText.obtain();
    }
    
    void finish() {
        mMeasured = MeasuredText.recycle(mMeasured);
    }

    private int mLineCount;
    private int mTopPadding, mBottomPadding;
    private int mColumns;