Prevent possible memory leak in SpanSet

If SpanSet.init() is called several times in a row with different
values, it is possible to change "numberOfSpans" in a way that
will prevent SpanSet.recycle() from nulling out all the spans.

This can lead to memory leaks of large objects through spans
references. User @piwai reported this leak:

     com.squareup.marketfont.MarketSpan
     `-[1] of array android.text.style.CharacterStyle[]
       `-spans of object android.text.SpanSet
         `-mCharacterStyleSpanSet of object android.text.TextLine
           `-[1] of array android.text.TextLine[]
             `-sCached of class android.text.TextLine

The MarketSpan instance is kept alive through a recycled TextLine
which itself contains a SpanSet.

Change-Id: Idfb2233ca16895dbe735c312662eaf0b4a2ecd65
1 file changed