Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Turned out, this question is not easy to formulate for me, but let's try.
In Android, pretty much any UI object depends on a Context, and has defined lifetime. Android can also destroy and recreate UI objects and even whole application process at any time, and so on. This makes coding asynchronous operations correctly not straightforward. (and sometimes very cumbersome) But I never have seen a real explanation, why it's done that way? There are other OSes, including mobile OSes (iOS, for example), that don't do such things. So, what are the wins of Android way (volatile UI objects and Contexts)? Does that allow Android applications to use much less RAM, or maybe there are other benefits?

share|improve this question
    
I agree, that android has a lot to do with memory saving. But why do you think that the passed around Context has something to do with memory saving? For me Context looks like a sandbox-api that allows accessing andriod app resources. –  k3b Jul 29 at 22:41

1 Answer 1

You are right about using "less" memory but it's not just less, but a fixed upper bound to each process's heap size. That means normal Java garbage collection can operate inside every instance of the Java runtime, without coordination with other processes. It also means processes can be the sandbox boundary for Android apps.

This has proven to be more successful than implementations of multi-tasking VMs, and other approaches for sharing a single VM among multiple applications.

Android's multi-process approach is made possible by Zygote. Zygote enables fast startup of an Android runtime by having most of the base classes loaded. You don't even copy the heap since Android runs in copy-on-write mode. It's pretty cool that processes, multiple runtime instance (LOTS of runtime instances compare to any other Java environment), and limited heap size all work together so well.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.