Skip to content

Low Memory?

Jacksgong edited this page Jan 8, 2017 · 10 revisions

We covered all low memory cases follow Processes and Threads, just feel free to use the FileDownloader, it will be following yours expect.

UI PROCESS

FileDownloader has very little data in this process, it just some running tasks objects.

UI Process is killed when it is Foreground process:

This case is almost impossible.

UI Process is killed when it is Background process:

This is a normal case. If your application is back to the background, the process is a background process, the system can kill them at any time to reclaim memory for a foreground, visible, or service process, so FileDownloader has been handled this case split to two situations:

  1. When there are tasks running on Serial-Queue: When the UI process has been killed, the FileDownloadService Process(which is a service process) will continue to download some tasks have been posted to the FileDownloadService( you have received pending status for it ) and some tasks have not been posted to the FileDownloadService will be interrupted. Rescue Experience: You can feel free to start the whole Serial-Queue again like before when your application is launched after that, FileDownloader will continue to download.

  2. When there are tasks running in parallel: When the UI process has been killed, the FileDownloadService will continue to download all tasks( because of they are all downloading in parallel and the action of posting task to FileDownloadService is very short ), but because of the UI process is missing, so you can't receive any callback now. Rescue Experience: You can feel free to start all tasks like before when your application is launched after that, and now you can receive all callbacks from now on normally.

DOWNLOAD PROCESS:

There is also very little memory is occupied on the Download process.

The Download process is always a service process unless you invoke FileDownloader#unBindServiceor FileDownloader#unBindServiceIfIdle to let it become an empty process(the system kill this kind of process very often), or you invoke FileDownloader#startForeground() to let it become a foreground process(the system will keep this kind of process alive as far as possible).

If the download process is killed when there are some tasks is downloading, because the FileDownloadService is START_STICKY Service, so the service will be restarted immediately, and in this time, if your UI process is alive, we have stored all interrupted tasks in the UI process, so we will try to continue to download all interrupted tasks.