Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User wiix's Avatar
    Join Date
    May 2008
    Posts
    1
    Hi,
    Im having a lot of trouble with the mobile phone application is throwing a java.lang.OutOfMemoryError.
    More specified:
    Code:
    Exception in thread "Thread-8" java.lang.OutOfMemoryError: Java heap space
    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.

    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();
            }
        }
    }

  2. #2
    Registered User Saxer's Avatar
    Join Date
    Jun 2008
    Posts
    5
    I'm experiencing the same problem. Only a phone restart can help.

    Do you have been able to found a solution yet?

  3. #3
    Registered User livelab's Avatar
    Join Date
    Dec 2007
    Posts
    4
    Why don't you try with HttpConnection?
    Then an InputStream.

    c = (HttpConnection)Connector.open("http://vg.no");
    s = c.openInputStream();

  4. #4
    Nokia Developer Moderator r2j7's Avatar
    Join Date
    Aug 2007
    Posts
    1,595
    Hello wiix and Saxer,

    to start with, which devices / platform (S60 or Series 40) are you referring to?

    For S60, it's advisable to check the memory using system property "com.nokia.memoryramfree" as instead of Runtime.getRuntime().freeMemory(), see here for explanation:

    http://wiki.forum.nokia.com/index.ph...ory_in_Java_ME

    If this is about Series 40 devices, the heap size is more limited than in S60 devices.

    As for garbage collection, using System.gc() does not guarantee that JVM will activate garbage collector, its up to JVM to decide to whether to run it or not:

    http://wiki.forum.nokia.com/index.ph...ory_management

    Saxer, are you referring to some specific device? For N95, there this Known Issue in Forum Nokia Wiki:

    http://wiki.forum.nokia.com/index.ph..._the_Nokia_N95


    Regards,
    r2j7

Similar Threads

  1. calling midlet from midlet throws SecurityException on 6600
    By brianpegan in forum Mobile Java General
    Replies: 3
    Last Post: 2010-10-25, 05:31
  2. java.lang.OutOfMemoryError while running through the memory profiler
    By plaporte in forum Mobile Java Tools & SDKs
    Replies: 1
    Last Post: 2007-09-20, 10:06
  3. Replies: 2
    Last Post: 2004-11-17, 10:20
  4. What can we learn from this ?
    By dtianx in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2004-04-28, 03:45
  5. can not successfully link any sample using .NET
    By lobotomat in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2002-08-20, 00:29

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved