×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Regular Contributor
    Join Date
    Aug 2003
    Posts
    127

    Memory issues s40

    Hi there
    After writing a game on s60 i tried to modified it to run on s40 but still i can't manage to get the Garbage collector to free memory. Example:
    Image bigPng = Image.createImage(.....);

    .....
    .....
    bigPng = null;
    System.gc();


    Whats wrong???
    MChmielewski

  2. #2
    Regular Contributor
    Join Date
    Mar 2003
    Location
    Rotterdam, Holland
    Posts
    118
    Image resources arent necessarily freed upon garbage collection. Note that garbage collection only makes sure objects that cant be referenced from any live thread are cleaned up. It is the responsibility of the platform/system to clean up resources such as graphics contexts etc., not the VM's. This said, it should theoratically clean those resources up reasonably quick after gc-ing. Although i have to admit i never ever used a single System.gc() in my code and never run into such memory problems, and i have made quite a few graphically intensive apps.

  3. #3
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395
    Since the image data is held in the Java heap, gc'ing should clear it once it is unreachable. In fact, if you subsequently need more memory that is "free", gc should occur anyway. Have you checked the free memory before and after gc'ing? Will freeing this image release enough memory for whatever you want next?

    Graham.

  4. #4
    Regular Contributor
    Join Date
    Aug 2003
    Posts
    127

    Next question?

    This midlet is a game so it needs some graphics objects. I load them from PNG files and many times since i started writing games i had problems with the OutOfMemory Exception especially when You choose another option from the main menu Such as Info about the game or Score board etc. So always after exiting to menu i call a cleanUp function to sweep the garbage but this does not help. When i test my game on nokia emulator i use extendet view of memory and register any changes. Do You know better way to closely inspect Your midllets memory needs???
    If so write to me please.

    Mchmiel

  5. #5
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395
    You can use Runtime.freeMemory() to find out how much memory is available. (But this is the total, not the largest free block, so you may not be able to use this much in one go if memory is fragmented.)

    Graham.

Posting Permissions

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