×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    4

    Are repeated calls to Image.getGraphics allowed ?

    If you call repeatedly the method Image.getGraphics() of a single image in the Series 60 MIDL implementation, the method throws an ArrayIndexOutOfBoundsException at some time.

    Is this a standard conforming behavior?
    Is it not allowed to call this method more than a few times?

    Example:

    In the following method, the call img.getGraphics() throws the exception when y=18. Is reproduceable with the Series 60 MIDL emulator and on the Nokia 3650 device. All other emulators I have tested do not throw an exception.

    private void repaintImage() {
    int sizey = getHeight();
    int sizex = getWidth();
    Image img = Image.createImage(sizex, sizey);
    for(int y=0;y<sizey;y++) {
    Graphics g = img.getGraphics();
    g.setColor(208);
    g.drawLine(57, y, 57, y);
    }
    }

    Moving the line 'Graphics g = img.getGraphics();' out of the loop
    removes the exception.

    The API documentation just says that at each call a new object is created at each call of Image.getGraphics() and that the object has an indefinite lifetime. Though I would expect that unused objects are garbage collected...

    Hans

  2. #2
    Regular Contributor
    Join Date
    Mar 2003
    Location
    Helsinki.FI
    Posts
    112
    Hi Hans,

    please refer to our technical note about memory issues with current Series 60 devices. Due to heap memory management devices may run into weird problems if memory consuming calls (such as getGraphics() is as it will always create a new Graphics instance) are being made extensively. I believe this seemingly non-relating ArrayIndexOutOfBoundsException relates to this also.

    You can find the technical note from http://www.forum.nokia.com/ -> Java -> Documents and there it is.

    Kind regards,
    Tinke / FN

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    4
    Thanks Tinke,

    I agree that the fix described in this document might cause the exception.

    Best regards,

    Hans

Posting Permissions

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