O'Reilly logo

High Performance Android Apps by Doug Sillars

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 5. Memory Performance

At the end of Chapter 4, we examined an issue where processes in the app blocked the UI thread, preventing the screen to update. In this chapter, we’ll look at how to measure and better understand how your app uses memory. Memory leaks are a major cause of crashes on Android, and using the tools discussed in this chapter to diagnose issues will help you prevent such leaks. Let’s kick off the discussion with memory management and tips to optimize, and then in the second half of the chapter, we’ll cover how to minimize the CPU usage of your app.

Android Memory: How It Works

Before we can discuss how to improve the memory efficiency of your Android app, we need to start with the basics on how Android handles memory management. Once we get a solid background on that, we can understand some of the pitfalls and how to resolve them. To introduce some of the basic terms, let’s get some simple information from your Android device.

As you may be aware, the Java runtime on your Android device (whether Dalvik or ART) is a memory-managed environment. The runtime typically handles all memory allocations and cleanup (garbage collection). This does simplify the development of your app by abstracting those details from your code, but there are important considerations to take while building your app to ensure that the memory management works correctly.

Let’s start with a quick set of definitions on the types of memory that are utilized by Android apps.

Shared Versus ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required