Frage

recently, I am testing the performance of swap partition for android device. I need to eat up all the memory in a test application(can has root authority), so that some pages can swap out. how can I do this? thanks.

War es hilfreich?

Lösung

Since you are able to use ADB and have busybox you may be able to use a shell script that allocates memory until it's exhausted.

refer to Write a bash shell script that consumes a constant amount of RAM for a user defined time

ripped from that answer:

#!/bin/ash

echo "Provide sleep time in the form of NUMBER[SUFFIX]"
echo "   SUFFIX may be 's' for seconds (default), 'm' for minutes,"
echo "   'h' for hours, or 'd' for days."
read -p "> " delay

echo "begin allocating memory..."
for index in $(seq 1000); do
    value=$(seq -w -s '' $index $(($index + 100000)))
    eval array$index=$value
done
echo "...end allocating memory"

echo "sleeping for $delay"
sleep $delay

Andere Tipps

load a bunch of bitmaps into memory, without weak references

Bitmap b = BitmapFactory.decodeResource(R.drawable.someresource, null);

or if you want to load from the disk

Bitmap b = BitmapFactory.decodeFile(filenamestring);

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top