EditText addTextChangedListener cause memory leak

I use LeakCanary to check my app for memory leak, and it reports a leak as follow EditText addTextChangedListener cause memory leak

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; }

the code calls setEnable(true) to add addTextChangedListener for TextView and i have already added setEnable(false) to removeTextChangedListener, but this is not enough, there is a static TextLine.sCached reference, how to release the sCashed.

The follow code snippet I found in 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; }

but, how to use it in correct way to recycle the static sCashed?

-------------Problems Reply------------

I found a related topic Android memory leak on textview

the Utils.clearTextLineCache() maybe a good workarounds.

Category:android Views:5 Time:2018-07-04

Related post

  • Will the below code cause memory leak in c++ 2008-09-29

    class someclass {}; class base { int a; int *pint; someclass objsomeclass; someclass* psomeclass; public: base() { objsomeclass = someclass(); psomeclass = new someclass(); pint = new int(); throw "constructor failed"; a = 43; } } int main() { base t

  • Can Delegates cause memory leaks? 2010-02-09

    Can Delegates cause memory leaks? I mean, by e.g. if a class A contains a ADelegate and the latter points to the BMethod (of B class) can this prevent the A class or B class collection by the GC? If so, how can we "free" delegates (setting ADeletate

  • Resources to read about Databinding causing memory leaks in WPF? 2010-03-10

    My wpf app is eating memory every time the ItemsSource of a TreeView is replaced (I simply construct a new object and assign it to the bound property). Furthermore the memory hoarding only occurs when I use a DataTemplate that is used in other ItemCo

  • NSMutableArray for Object which has NSString property causes memory leak 2010-04-22

    I hope to add objects to a NSMutableArray "myArray", The NSMutableArray is the array for FileObj which has a NSString property "fileName" #import <UIKit/UIKit.h> @interface FileObj : NSObject { NSString *fileName; } -(void) setfileName:(NSStrin

  • remove rows of UITableView causes memory leak 2010-04-23

    I hope to delete all rows of an UITablewView The UITableView is "atableview", its data source is "fileArray". NSMutableArray *fileArray; fileArray is NSMutableArray for object MYFileObj #import <UIKit/UIKit.h> NSMutableArray *fileArray; @interf

  • Using WeakReference to resolve issue with .NET unregistered event handlers causing memory leaks 2010-05-11

    The problem: Registered event handlers create a reference from the event to the event handler's instance. If that instance fails to unregister the event handler (via Dispose, presumably), then the instance memory will not be freed by the garbage coll

  • c++-to-python swig caused memory leak! Related to Py_BuildValue and SWIG_NewPointerObj 2010-06-02

    I have the following Swig code that caused memory leak. PyObject* FindBestMatch(const Bar& fp) { Foo* ptr(new Foo()); float match; // call a function to fill the foo pointer return Py_BuildValue( "(fO)", match, SWIG_NewPointerObj(ptr, SWIGTYPE_p_

  • Does remove a DOM object (in Javascript) will cause Memory leak if it has event attached? 2010-06-08

    So, if in the javascript, I create a DOM object in the HTML page, and attach event listener to the DOM object, upon I remove the the DOM from HTML page, does the event listener still exist and causing memory leak? function myTest() { var obj = docume

  • How do events cause memory leaks in C# and how do Weak References help mitigate that? 2010-09-07

    There are two ways (that I know of) to cause an unintentional memory leak in C#: Not disposing of resources that implement IDisposable Referencing and de-referencing events incorrectly. I don't really understand the second point. If the source object

  • Are my subclasses causing memory leaks? 2010-11-29

    I'm subclassing UINavigationController and UITableview and for some reason, my views are leaking memory, although I've implemented all of the proper methods and release calls. When I use the native class instead of a subclass, everything works just f

  • MKMapView removeAnnotations cause memory leak 2011-01-31

    everyone! I have tested this simplest code as following: StorePin.h #import <Foundation/Foundation.h> #import <MAPKIT/mapkit.h> #import <CORELOCATION/corelocation.h> @interface StorePin : NSObject <MKAnnotation> { CLLocationCo

  • Does this objective-c code cause memory leak? 2011-02-05

    Compare the following 2 snippets: sample 1: [[UIApplication shareApplication] openURL: [NSURL URLWithString:@"http://stackoverflow.com"]] and sample 2: NSURL *url = [[NSUrl URLWithString:@"http://stackoverflow.com"]; [[UIApplication shareApplication]

  • Will DynamicResource cause memory leak? 2011-04-02

    Will dynamicresource cause meomry leak?. Expression Blend is using mostly DyanamicResource instead of StaticResource. I read from different docs saying that use StaticResource to avoid memory leak?. If it is true then why expression blend is heavily

  • Will delete[] with void* cause memory leak? 2011-04-27

    Possible Duplicate: Is it safe to delete a void pointer? Will the following code cause memory leak? void *ptr = new long [10]; delete[] ptr; // note: ptr is a void* [EDIT] The code above will generate a warning message during compiling to specify it

  • Does circular references cause memory leaks in JavaScript? 2011-05-28

    I've read many claims stating that circular references will cause memory leaks: http://www.ibm.com/developerworks/web/library/wa-memleak/ http://www.quirksmode.org/blog/archives/2005/02/javascript_memo.html http://www.javascriptkit.com/javatutors/clo

  • what causes memory leak in java 2011-06-08

    I have a web application deployed in Oracle iPlanet web server 7. Website is used actively in Internet. After deploying, heap size is growing and after 2 or 3 weeks, OutOfMemory error is thrown. So I began to use profiling tool. I am not familiar wit

  • Updating DOM via Javascript causing memory leaks (only in Firefox?) 2011-06-25

    I know this question has been asked before, but none of the answers seem to resolve the issue. I'm testing an AJAX webpage which updates elements in the DOM via javascript. Every minute, the server is queried for new data and the DOM is updated accor

  • can a thread which runs indefinatley cause memory leak? 2011-08-17

    I have a j2ee application and inside which i have a class 1 which starts multiple threads T1 ,T2 ,T3.Now i also have a webserrvice.Now I want that that my threads T1,T2,T3,should run indevinitely till the webserver is stopped or my application is und

  • Opacity and filter causing memory leak in IE7 2011-09-16

    I have a div defined as <div id="block_screen">&nbsp</div> there is a stylesheet associated with its id #block_screen { position: absolute; background-color: #000; height: 100%; width: 100%; top: 0; left: 0; z-index: 9997; opacity: 0.

  • Will this javascript cause memory leak? 2011-10-02

    function outer(){ var a, b, c; function inner1(){ ... } function inner2(){ ... } inner1(); inner2(); ... } I want to keep the global namespace clean so I wrote above code. Inner functions are only used by code inside Outer. But after that I begin to

  • is these code cause memory leak in java? 2011-10-18

    ArrayList<Object> list = new ArrayList<Object>(); for (int i = 0; i < 10; i++) { Object o = new Object(); list.add(o); } list = null; or ArrayList<Object> list = new ArrayList<Object>(); for (int i = 0; i < 10; i++) { Ob

  • C++, will this cause memory leak? 2011-12-08

    I know that I can't get a reference of a local var. such as: int& func1() { int i; i = 1; return i; } And I know that this is correct, but I have to delete it after calling func2() int* func2() { int* p; p = new int; *p = 1; return p; } int main(

  • Will List cause memory leak? 2011-12-14

    I have a function that takes in a list of functors: public void RunFunc(List<Func<double, double>> functorList) The thing is that the Func<double, double> are assigned with methods from different objects. My concern now is that the

  • Could loading nib incorrectly in MonoTouch cause memory leaks? 2011-12-16

    I am creating my first app using MonoTouch. It is fairly simple app that searches for a code from an sqlite database and brings up various meanings for the code on different views. I've used Interface Builder. My question is regarding the correct way

  • examples of closures in node.js that would cause memory leaks 2012-01-11

    In trying to debug memory leaks in NodeJS, I'm finding it quite difficult (given the lack of profiling tools that I am aware of). I thought I'd go back to basics and make sure I understand how a memory leak would be created specifically in NodeJS. I'

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.151 (s). 11 q(s)