android - How garbage collector release AsyncTask allocated memory -


In main activity, I am creating a new asynchronous x and I with new RTask (this) I execute Executed (the ultimate); To send data to a server incomparably, I think creating a new task can often lead to memory leaks. So when the garbage collector releases memory and how can I set up the work reference to allow it to be collected? I have tried to use this.cancel (true); inside onPostExecute () but I've read that, due to a bug in the Android Framework, OPtest is never called.

Actually, there should not be any reference from param Or doInBackground () .

Then, you might think that if you are building many long-running AsyncTasks, then take it on some memory issues. Will go Actually this is not true (at least on the latest Android version) AsyncTask shows that

  • This uses the Singleton Bound Executor:

      Private Stable FINAL INC. CORE_POOL_SIZE = 5; Private static final integer MAXIMUM_POOL_SIZE = 128; Private stable final end KEEP_ALIVE = 1; Public stable final executor THREAD_POOL_EXECUTOR = New Threadpool Explorer (CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE, time unit. SEODDS, SPWalkerQ, STredFacture);   

    This means that the executor will not run more than 128 AsyncTasks at the same time (128 is not too big according to my understanding).

  • It uses the loaded query for the executor:

      Private static last blocking keys & lt; Runnabel & gt; SPoolWorkQueue = New Linkboxing Qualify & lt; Runnabel & gt; (10);       

    So, based on the above points, is limited and is not so big, so if your code inside asyncTask has not created a memory leak, then there is no issue as per my understanding. At the same time, Android will not let you spam yourself with AsyncTasks . Checkout to be familiar with the way it manages a memory (if you worry about a lot of built-in threads at the same time)

    Especially in your case, I do not think it is a good idea to execute each other by requesting the server, while the last one has not yet been completed (similar requests ), Even if there are many things to do with small requests sometimes it does not make sense - your app will attract the battery very fast in this case.

    Cancel () on the basis of:

    Cancel the job

    Canceled (boolean) at any time Can be canceled by turning on. The incoming calls will be canceled after incorporating this method () to return true. After applying this method, after the OnInBround (object []) returns, the object will be brought to the canceled (object) instead of PostExecute (object). To ensure that a work has been canceled as soon as possible, you should always check the check value of the value to be canceled (from time to time). If possible (for example, inside a loop).

    So, I'm not sure that you mean "I have tried to use this console (true); onPostExecute ()" while cancel () to do nothing if it is called from onPostExecute () , it can be called from AsyncTask or doInBackground () and There is a good practice to call if you have a loop in AsyncTask cancel () . Stop execution once

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -