[mono-android] Tracking GlobalReferences
Jonathan Pryor
jonp at xamarin.com
Tue Feb 14 22:06:30 UTC 2012
On Feb 5, 2012, at 11:48 AM, NebulaSleuth wrote:
> As for the "other" leak I mentioned with strings, it seems to be related to changing the "text" property of a TextView.
>
> as in: "TextView.Text = TranslationLookup(TextView.Text);"
The problem isn't the property set. The problem is get_Text(), as it creates an ICharSequence wrapper which holds a gref. (We should probably optimize that...)
As a workaround, you can instead do:
var text = TextView.TextFormatted; // contains gref
TextView.Text = TranslationLookup(text.ToString());
((IDisposable) text).Dispose();
> But, this seems to allocate a new GRef, and doesn't free up one. These stale
> grefs get freed when I launch a new activity
The problem is that it isn't "stale" -- it's a perfectly valid, referenced, gref. It just happens to be one that you don't care about. :-)
Disposing of it (as shown above) will remove it.
- Jon
More information about the Monodroid
mailing list