×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    3

    Memory leak when unloading and loading images

    Hi,

    I've been doing some tests to try to find out why my application using jsr184 can start with 12 - 13 fps (very high quality graphics on n95) and drop to 3-4 fps. It appears that as images are loaded and unloaded the fps drops each time. If I allow the application to idle it does not lose any e rate, but as I progress through the application (images load and unload as the application goes from one menu screen into game and back), the frame rate drops drastically, including loading/unloading images for textures.

    I would assume that there is a memory leak with the native phone memory used to store images that are loaded in a java app (someone mentioned that some nokia series store images on a seperate heap to the rest of the app.

    Has anyone encountered this issue and found a way round it (other than loading all images into memory and keeping them there).

    Cheers

    Jules.

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Memory leak when unloading and loading images

    Hi Jules!

    How's it going? Same game, different day???

    Hmmmm... I don't think the N95 leaks with Image objects, that's more an issue of the old MIDP-1 60s. But: a lot of 60s do leak memory with 3D objects. This might also relate to texture images. I suspect the garbage collection doesn't propagate from the Java world into the C world of OpenGLES.

    This usually results in out-of-memory issues rather than a slow down. But you should avoid unloading anything 3D-related anyway. (Preferably, build the code so you can unload for lower-memory, non-Series-60 devices, or cache everything for leaky Nokias.) Don't dynamically create or modify models... this becomes a nightmare.

    You should be able to ditch images that don't relate to 3D quite happily.

    I don't think it relates to your issue, but it is worth reading M3G performance hints for 3D hardware-accelerated devices (Nokia N93 and Nokia N95)
    (if you haven't seen this already).

    Cheers,
    Graham.

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    3

    Re: Memory leak when unloading and loading images

    Hi Graham,

    Sorry I havnt answered earlier, things have been manic, mainly with trying to accomodate a rather large wish list for the next pool game.

    Its beginning to look like a less than desirable System.gc() implementation on the n95. It may be due to references not being dereferenced, but I'm pretty sure all are nulled properly. Also, the gc() on n95 seems very slow in comparison to 6280, which doesnt bode well for a JIT resource loading system (can become very jittery). Looks like the only way to make decent games with short loading times on n95 is to go with s60 programming and handle your own pointer and memory allocations, maybe one day we'll start programing on symbian, but till then I think i'm going to have to bulk load between game and menu.

    So what u up to these days?

    Jules.

  4. #4
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Memory leak when unloading and loading images

    Avoid calling System.gc() on Series 60s... it is very much slower than on Series 40s. This is because 40s use a small, single heap, while 60s use a segmented heap, with a small segment for new and short-lived objects, and a large (extending) segment for longer-lived objects.

    You'll find this documented as a "generational heap". When the "new object heap" gets full, there is an automatic gc of that heap only. Because the new heap is small, this happens frequently and is brief, so you shouldn't get jitters. If you manually call System.gc(), the implementation does a full garbage sweep of all heaps... this is what takes a long time.

    (This is a good candidate for a build-time option:
    Code:
    if (Device.USE_MANUAL_GC) {
        System.gc();
    }
    where "USE_MANUAL_GC" might be true for devices like the 6280, but will be false for Series 60s.)

    You will have problems with 3D objects... they will leak if you try to unload them.

    If you want to avoid a long "loading" screen, you might try starting the load on a separate thread - set the priority low so it doesn't interfere too much with the menu. You could start this as soon as you have all the essential stuff loaded, everything you need to make the menu work. If it works, make it a build-time optional feature... some devices will probably block all threads while the loading happens, so will need to defer loading until the game itself is started.

    Talk to you soon,
    Graham.

Similar Threads

  1. Where does the class load in Memory and How much Memory Consume
    By sharma_durg in forum Mobile Java General
    Replies: 2
    Last Post: 2006-10-13, 22:34
  2. Loading / Unloading classes into heap
    By itsik78 in forum Mobile Java General
    Replies: 1
    Last Post: 2003-11-13, 12:40

Posting Permissions

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