Android Memory Management

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 7

ANDROID MEMORY

MANAGEMENT
Memory managementis a serious issue for Java development.
When it comes to Android, though, things are a little different:
consequences are limited to your individual app, rather than
system-wide catastrophes. That means you might need some
different strategies, and thisrecent articlefrom Joe Mahon at
Raizlabs provides a few tips to help you out.

1. SEARCH FOR MEMORY LEAKS EVEN WHEN THINGS AREN'T FAILING

2. KEEP TRACK OF YOUR REFERENCES

3. BE AWARE THAT THE ANDROID GARBAGECOLLECTOR IS CLUMSY

4. DON'T HANG ON TO REFERENCES TO ACTIVITIES


Sharing Memory

1. Each app process is forked from an existing process called


Zygote. The Zygote process starts when the system boots and
loads common framework code and resources (such as activity
themes).

2. Most static data is mmapped into a process. This technique


allows data to be shared between processes, and also allows it
to be paged out when needed.

3. In many places, Android shares the same dynamic RAM across


processes using explicitly allocated shared memory regions
(either with ashmem or gralloc).
ALLOCATING AND RECLAIMING APP MEMORY
RESTRICTING APP
MEMORY
THANK YOU
SWITCHING APPS

When users switch between apps, Android keeps apps that are not
foregroundthat is, not visible to the user or running a foreground service
like music playback in a least-recently used (LRU) cache. For example,
when a user first launches an app, a process is created for it; but when the
user leaves the app, that process doesnotquit. The system keeps the
process cached. If the user later returns to the app, the system reuses the
process, thereby making the app switching faster.

If your app has a cached process and it retains memory that it currently
does not need, then your appeven while the user is not using it affects
the system's overall performance. As the system runs low on memory, it
kills processes in the LRU cache beginning with the process least recently
used. The system also accounts for processes that hold onto the most

You might also like