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.
Asked
Active
Viewed 223 times
2 Answers
1
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);

Lena Bru
- 13,521
- 11
- 61
- 126
-
very instructive, I was trying to use [new] – Sky Apr 28 '14 at 14:51
-
I'm pretty sure they want to use all the memory in the system, not just by the app. this will give an out of memory exception when it hits the app's limits. – John Boker Apr 28 '14 at 14:52
-
do you know how many posts are out there for "Out of Memory Error" on this issue ? – Lena Bru Apr 28 '14 at 14:53
-
I don't think the system will let him eat up all the memory in the system. just for the app itself. Depending on the device it can vary from 40 megs to 1gb – Lena Bru Apr 28 '14 at 14:54
-
I agree, which means this answer does not answer the question. – John Boker Apr 28 '14 at 14:54
-
using adb, can I achieve this goal? I have busybox @JohnBoker – Sky Apr 28 '14 at 15:32
1
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

Community
- 1
- 1

John Boker
- 82,559
- 17
- 97
- 130