Akshat
Akshat

Reputation: 4673

Simulate Out of Memory in android

This is the case when I want to simulate an Out of memory crash in my application. I have a lot of crashes from Crashlytics which indicate that end users are running into OOM crashes and I have not been able to reproduce them with my device (Samsung S4). I just have crashes and no other traces from crashlytics.

I was wondering if someone has a way to reproduce them for their testing (without any code change preferred).

I saw this : Testing Android for Out of Memory scenarios , but haven't got a chance to run it yet.

Any help would be appreciated.

Upvotes: 6

Views: 4542

Answers (3)

Booger
Booger

Reputation: 18725

There are a variety of ways to cause OOM.

  1. Use a very large image (incidentally, this use-case is a source of many real OOM issues in apps). I replaced the image for 1 element in my Recycler, so when I scroll to it, it will load the large image (then I can drive the test that way).

  2. Create a loop, that allocates objects to memory. You can just "new" up a bunch of objects in a loop, and run it that way. If you allocate enough Strings, or int objects into a single array, this will run OOM eventually (this is also a good way to gradually build to an OOM condition). Strings will cause OOM faster then ints (but add enough objects to an array, and eventually it will become too large).

Upvotes: 4

Chris Gunawardena
Chris Gunawardena

Reputation: 6468

I was able to simulate the OOM error by replacing a list of images in the app very large images. 5mb instead of usual 250k. Wikimedia has lot large images you can use. https://commons.wikimedia.org/wiki/File:Snake_River_(5mb).jpg

Upvotes: 2

lawonga
lawonga

Reputation: 832

I hope I'm understanding the question correctly: There's a very easy way if you don't want to change a lot of settings. Go into dev options and make it "no background processeses". Now you can exit out of the app, launch a new one and go back into your original and it'll be wiped out from out of memory

Upvotes: 0

Related Questions