java - android anonymous asyncTask - will it cause memory leak -


in android trying prevent memory leak. inherited legacy code , in developer creating asynctask anonymous inner class this:

 void startasynctask() {     new asynctask<void, void, void>() {         @override protected void doinbackground(void... params) {             while(true);//loop  keep thread alive forever.         }     }.execute(); } 

so using loop in example keep child thread alive forever can demo point. activity if call startasynctask() there memory leak ? class not have activity reference realize anonymous class non-static inner class , holds reference outer class. true memory leak ?

it hold reference outer class (the activity) until task finishes. cause activity held longer absolutely necessary. if task finishes in reasonable amount of time, ought ok- after finished task on , become garbage collectable, make activity garbage collectable. bigger concern long term threads can last past end of activity, or not terminate @ if poorly written.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -