On-device low-memory testing for Android

Overview

Android Developer Toolbelt

On-device low-memory testing for Android. Fill your phone's RAM and see how your application performs. Download the app, tap the Fill Memory button, and re-open your app - hopefully nothing breaks :)

Why?

In my expierence this is where the majority of bugs in Android applications are found. It's also one of the hardest and most time consuming things to test. If you're getting large volumes of seemingly un-reproducable crashes in your logs, my bet is it's something to do with your app being put into a background state.

How to Test Your App

There are three main ways this tool can be used to test your app:

  1. Testing your Application/Activities being placed into background.
  2. Testing your process being killed (i.e. everything in memory, including all static variables will be removed).
  3. Testing your app while under memory pressure (maybe more useful for games).

To test cases 1 & 2, use the instructions below. For testing while under memory pressure, just don't press the stop button (unfortunately this can sometimes lead to freezing issues on some devices)[2].

  1. Start your application and build up some state you want to test i.e. play with it a little.
  2. Start this app & tap the Fill Memory button. You'll see the memory counter decrease. When it hits a point when it seemingly cannot go any lower or the low memory indicator is true[2], your app has probably[3] been placed into a background state.
  3. Press the Stop button and return to your app to ensure all state has been properly restored.

[1] I'm planning on adding a Pause button soon, so that the memory level can be kept constant - which should make this kind of testing much easier.

[2] Not all devices will be able to reach the state where the 'Low Memory' indicator is true. This is an indicator for the operating system as a whole, not specific applications. Your app can still be placed into background as normal (when the indicator can't seem to go much lower).

[3] Android kills applications using different criteria - I can't guarantee when it will kill your app, the longer you wait, the more likely your app has been killed. When you notice the RAM counter bouncing up and down (~10% mark on a Nexus 5), you know that Android is freeing up memory by killing applications & services.

Under the Hood

If you want to fill an Android device's memory - there are two methods of programatically doing this (that I know of):

  1. Use the NDK and malloc() to fill the native heap.
  2. Use multiple processes and fill the standard Java heap for each one.

I opted for the latter method for two reasons:

  1. Easier to control. Less chance of doing something stupid and having memory that doesn't get cleaned up when finished testing.
  2. My experience with similar apps seems to indicate that the native heap hits an upper limit memory usage (~1Gb). On recent devices, this sometimes isn't enough to trigger the low-memory state.

In order to get the application to run in multiple process I'm using multiple Services, each with a seperate android:process attribute set in the manifest. Normally this would mean writing code for ~20 Service classes, but that's where code generation comes to the rescue! The compiler module handles generating the source code for these classes.

License

Copyright 2015 Oisín O'Neill

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
You might also like...
Android MVVM framework write in kotlin, develop Android has never been so fun.

KBinding 中文版 Android MVVM framework write in kotlin, base on anko, simple but powerful. It depends on my another project AutoAdapter(A library for sim

Klimatic is an android app built using Kotlin. It try to showcase all the latest technologies used in android.
Klimatic is an android app built using Kotlin. It try to showcase all the latest technologies used in android.

Klimatic Klimatic is an android app built using Kotlin. It try to showcase all the latest technologies used in android. Built using Android Architectu

Oratio Library for Android Studio helps you simplify your Android TTS codes

Oratio Oratio is a library for Android Studio. This library is useful to a number of developers who are currently making apps using android TTS(Text-T

This is a demo android app representing implementation of SE principles in android app development

Articles Demo This repository contains a sample Android App that shows most popular articles data from NY Times API. This is a sample app that shows h

Android-Boilerplate - Base project for android development with new technology

Android-Boilerplate Base project for android development with new technology, in

Gits-android-extensions - A collection of Kotlin extensions to simplify Android development

gits-android-extensions A collection of Kotlin extensions to simplify Android de

Android Clean Architecture in Rorty is a sample project that presents modern, approach to Android application development using Kotlin and latest tech-stack.
Android Clean Architecture in Rorty is a sample project that presents modern, approach to Android application development using Kotlin and latest tech-stack.

Android Clean Architecture in Rorty is a sample project that presents modern, approach to Android application development using Kotlin and latest tech-stack.

Android Ptrace Inject for all ABIs and all APIs. Help you inject Shared Library on Android.

Android Ptrace Inject 中文可以参考我的注释内容进行理解 我写的注释相对来说比较全面了 How to build Make sure you have CMake and Ninja in your PATH Edit CMakeLists.txt. Set ANDROID_ND

Pleasant Android application development
Pleasant Android application development

⚠️ Anko is deprecated. Please see this page for more information. Anko is a Kotlin library which makes Android application development faster and easi

Comments
A sample app showing different kind of memory leaks and their solutions

MemoryLeakApp A sample app showing different kind of memory leaks and their solutions. Make sure to check the source code to understand the concept of

Moradious 11 Oct 28, 2022
A simplified interface for interacting with in-memory cache implementations on the JVM

This library provides a simplified interface for interacting with in-memory cache implementations on the JVM. Think: "SLF4J but for caching"

null 5 Nov 29, 2022
Utility for developers and QAs what helps minimize time wasting on writing the same data for testing over and over again. Made by Stfalcon

Stfalcon Fixturer A Utility for developers and QAs which helps minimize time wasting on writing the same data for testing over and over again. You can

Stfalcon LLC 31 Nov 29, 2021
Successor to ProxyBuilder - Uses Spring & Netty for testing proxies, interacting with a local MariaDB.

Successor to ProxyBuilder - Uses Spring & Netty for testing proxies, interacting with a local MariaDB.

Kai o((>ω< ))o 8 Dec 6, 2022
A Kotlin multiplatform unit testing library inspired by / similar to Google Truth.

Truthish A testing API inspired by Google Truth but rewritten in Kotlin from the ground up, so it can be used in Kotlin multiplatform projects. For ex

Varabyte 70 Nov 2, 2022
Example code from coroutines testing talk.

Coroutines Testing This repo contains example code used to build my (Bill Phillips) talk on coroutines testing. Use it however you please, but note so

Bill Phillips 3 Nov 17, 2022
[Android Library] Get easy access to device information super fast, real quick

DeviceInfo-Sample Simple, single class wrapper to get device information from an android device. This library provides an easy way to access all the d

Anitaa Murthy 193 Nov 20, 2022
🔎 An HTTP inspector for Android & OkHTTP (like Charles but on device) - More Chucker than Chuck

Chucker A fork of Chuck Getting Started Features Multi-Window Configure Redact-Header️ Decode-Body Migrating Snapshots FAQ Contributing Building Ackno

Chucker Team 2.9k Dec 30, 2022
This library is a set of simple wrapper classes that are aimed to help you easily access android device information.

SysInfo Simple, single class wrapper to get device information from an android device. This library provides an easy way to access all the device info

Klejvi Kapaj 7 Dec 27, 2022
On-device wake word detection powered by deep learning.

Porcupine Made in Vancouver, Canada by Picovoice Porcupine is a highly-accurate and lightweight wake word engine. It enables building always-listening

Picovoice 2.8k Dec 30, 2022