In android i am trying to prevent a memory leak. I inherited some legacy code and in it the developer is creating a asyncTask as a anonymous inner class like this:
void startAsyncTask() {
new AsyncTask<Void, Void, Void>() {
@Override protected Void doInBackground(Void... params) {
while(true);//loop to keep thread alive forever.
}
}.execute();
}
so i am using a loop in this example just to keep the child thread alive forever so i can demo my point.
so from the activity if i call startAsyncTask()
will there be a memory leak ? the class does not have a activity reference but i realize that an anonymous class is really a non-static inner class and thus holds a reference to the outer class. so is it true that this itself is a memory leak ?