michelle michelle - 6 months ago 30
Java Question

onLowMemory event testing

I need a test to be able to see if I can somehow use up the system's entire memory so that the system invokes the

onLowMemory()
-event.

I need this to be able to test the behaviour of an application when the memory is running low.
Any tips?

Answer
List<Integer> memoryHog = new ArrayList<Integer>();
while(true){
   memoryHog.add(new Integer(5));
}

Would something as simple as that work? Basically loop and add objects until any memory allocated to your program gets used. Or are you looking for a way to literally use all the systems memory?