×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    4

    Creating custom items crashes Nokia 6630 jvm

    I have a simple program that creates 20 custom items (that do not draw anything), adds those items to a form and removes them again and begins from start.

    This program keeps crashing my 6630 jvm. If I do the same thing with a string item, the program works perfectly.

    It seems as if the frequency of crashes depends on the size of the custom item. If the custom item returns a larger size, the jvm will crash sooner.

    Clearly, this program does not do anything really useful, but I get the same behaviour in a larger program where I work a lot with custom items.

    Synchronizing on the display thread does not help. Similarily, throwing away the form and just adding items will also not solve the problem.

    Does anyone have a workaround for this problem?

    Here the code that I am using, just put it in the midlet's start method and enjoy the bug:

    final Form f = new Form("Hello");
    final Display d = Display.getDisplay(this);
    d.setCurrent(f);
    Thread t = new Thread() {
    public void run() {
    try {
    Thread.sleep(5000);
    } catch (InterruptedException e) {
    }
    while (running) {
    for (int i = 0; i < 20; i++) {
    f.append(new CustomItem("Hello") {
    protected int getMinContentHeight() {
    return 20;
    }
    protected int getMinContentWidth() {
    return 20;
    }
    protected int getPrefContentHeight(int arg0) {
    return 20;
    }
    protected int getPrefContentWidth(int arg0) {
    return 20;
    }
    protected synchronized void paint(Graphics arg0, int arg1, int arg2) {
    }
    });
    }
    while (f.size() > 0) {
    f.delete(0);
    }
    }
    }
    };
    t.start();

  2. #2
    Regular Contributor
    Join Date
    Jan 2005
    Location
    France, Paris
    Posts
    56

    Re: Creating custom items crashes Nokia 6630 jvm

    Did you try to catch an OutOfMemoryError? It's just a guess (and I don't really know much about how it works), but it may be possible that there's no memory left in the heap, and the GC is not fast enough to clean all the objects you create in your loop.

    Nicolas

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    4

    Re: Creating custom items crashes Nokia 6630 jvm

    The vm terminates, so there is nothing that you could catch.

  4. #4
    Regular Contributor
    Join Date
    Jan 2005
    Location
    France, Paris
    Posts
    56

    Re: Creating custom items crashes Nokia 6630 jvm

    When you get a OutOfMemoryError, that's what happens usually but you can still try to catch it, run the System.gc method, log the error in a record store inside the catch block...
    I don't know how the CustomItem is implemented, or how much it takes in the heap, but given to what you say (about the size, and the crash which could happen sooner), it seems like a memory problem.

    If it really is, I would create a class which would extend the CustomItem class, and then I would create a kind of object cache to reuse the custom items, instead of creating new ones at each loop...

  5. #5
    Registered User
    Join Date
    Jun 2006
    Posts
    4

    Re: Creating custom items crashes Nokia 6630 jvm

    I know you're trying to help, but this is not a memory problem. BTW, even if it was, terminating the jvm would certainly not conform to the java language specification.

  6. #6
    Registered User
    Join Date
    Jun 2006
    Posts
    4

    Re: Creating custom items crashes Nokia 6630 jvm

    After playing around with that buggy mobile phone, I figured out that there is a race in the Form.delete() method. If you replace the remove loop with the following:

    while (f.size() > 0) {
    f.delete(0);
    Thread.sleep(100);
    }

    everything works fine. Again, this is not a memory problem, if you put a Thread.sleep(10000) after the delete loop, it will crash anyway.

    So now to you "developers" from Nokia. Appart from that race condition, I was able to find 2 further bugs during the last 2 days:

    First: The Display.callSerially() method will forget every posted event except for the first one that is posted (maybe you should lookup the concept of a queue in a cs data structure book of your choice, you might even be able to use a java.util.Vector() to implement it in a hassle free way)
    Second: If you access a forms delete() method within the Runnable passed to callSerially, the ui will hang forever. There are some good books on synchronization, maybe you should read them, too.

    As it is not possible to code around this little "gliches" without writing my own gui toolkit, I will now officially throw away that bug-prone mobile phone. Since my salary is too low to make a fuss about two days work, I will simply throw away the invoice for my time.

    I think it is strange that I can find more system-level bugs in this little device in two days than I have found in desktop vms in my whole programmer's life. You should consider hiring a testing team.

    Furthermore, you should probably fire the people that are working in JCP group that made the lcdui-packages. Creating a thread-safe ui is probably the worst idea that I have ever heard of. Again, synchronizing the user interface is only half the way (this is even stated in the java docs of lcdui (!)), your application code also needs to be thread-safe. With a gui thread where you can post events, you have a simple, yet efficient interface to perform things in your application code serially. With lcdui, you have to do that kind of serialization in an application thread (oh, what a performance and memory benefit, thank you).

Similar Threads

  1. Nokia User Agent Header
    By rajendrap16 in forum Browsing and Mark-ups
    Replies: 17
    Last Post: 2008-02-24, 15:43
  2. Does Nokia 6630 supports Socket Connection?
    By kishorekadiri in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2006-02-21, 05:20
  3. Infra-red capability
    By Symbian_Challenge_0412 in forum General Development Questions
    Replies: 1
    Last Post: 2005-08-16, 18:24

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×