Android Anonymous Asynctask - Will It Cause Memory Leak
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 startAsyn
Solution 1:
It will hold a reference to the outer class (the Activity) until the task finishes. So it will cause the activity to be held longer than absolutely necessary. However if the task finishes in a reasonable amount of time, that ought to be ok- after its finished the task will be over and become garbage collectable, which will make the Activity garbage collectable. The bigger concern is long term threads which can last well past the end of the activity, or not terminate at all if poorly written.
Post a Comment for "Android Anonymous Asynctask - Will It Cause Memory Leak"