Hi,
Im having a lot of trouble with the mobile phone application is throwing a java.lang.OutOfMemoryError.
More specified:I am making an app on a mobile phone that is basically testing the mobile phone speed by connecting to a given set of URLS and tests the phones download speed, connection time, etc. The problem is, that after X amount of tests it throws the heap space error. It differs from computer to computer(on the emulator) how many tests I can run before it chokes and stops.Code:Exception in thread "Thread-8" java.lang.OutOfMemoryError: Java heap space
It seems like there is no difference if I stop the tests and continue, after for example one hour. Im wondering if there's a way to avoid this. The memory graph and Runtime.getRuntime().freeMemory() indicates that there is no trouble with the phones memory, I got plenty avaliable space (after gc()). So Im wondering what the problem is, and hoping you can help me solve it.
The way my program runs the test is pretty basic. The program actually downloads a test suite with a synchronize to the server to get a bunch of tests to run, so to avoid writing unnessesary code, Ive just written together a class that justs makes a bunch of connections and then closes them, without going through the stream. At this computer it goes haywire after 2085 tests, pretty much every time. As I said earlier, it doesnt matter how fast the tests goes, if I slow them down by putting in a this.wait(1000) before each connection, it still throws the exception.
Code:import java.io.InputStream; import javax.microedition.io.Connector; import javax.microedition.io.StreamConnection; public class BasicTest { private StreamConnection c = null; private InputStream s = null; public BasicTest() { test(); } public synchronized void test() { int counter = 1; int repeat = 10000; while (counter <= repeat) { try { //this.wait(1000) -- doesnt help c = (StreamConnection) Connector.open("http://vg.no"); //redirect domain to speed tests up s = c.openInputStream(); close(); if (counter % 5 == 0) { //prints test # only every 5 times System.out.println(counter + " -- " + Runtime.getRuntime().freeMemory() + " / " + Runtime.getRuntime().totalMemory()); } } catch (Exception e) { e.printStackTrace(); } counter++; } } private void close() { try { if (s != null) { s.close(); s = null; } if (c != null) { c.close(); c = null; } } catch (Exception e) { e.printStackTrace(); } } }

Reply With Quote

