0

I have an Android app to be tested for Memory usage. As a test case, I need to increase its memory usage(RAM) programmatically. What are the possible ways? Does increasing thread.sleep time in my app would increase the memory usage?

4
  • You want to increase the amount of memory the application uses, or increase the amount of memory the application is allowed to use ? Commented Oct 22, 2015 at 13:23
  • I want to increase the memory that app uses in RAM. Commented Oct 22, 2015 at 13:26
  • Integer[] i = new Integer[Integer.MAX_VALUE]; should do it. Commented Oct 22, 2015 at 13:31
  • 1
    Load an image. Memory usage will raise very quickly. The bigger, the greater OOM crash probability. Commented Oct 22, 2015 at 13:38

1 Answer 1

0

ByteArrayInputStream bais = new ByteArrayInputStream(new byte[1000]);

Creates a object in your memory that is 1000 bytes.

1000000 bytes is about 1mb

Sign up to request clarification or add additional context in comments.

4 Comments

This would increase the memory used by app in RAM?
It would add 1000bytes to your ram
I added this in one of the methods like this but no effect... public void test1_2(){ ByteArrayInputStream bais = new ByteArrayInputStream(new byte[1000]); }
That is because, as soon as the method ends, the memory is no longer needed and the garbage colector kicks in. Make it an attribute in your activity to keep it as long as the activity exists

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.