problem with applet and heap space

Started by mogli, August 26, 2006, 05:43:35 PM

Previous topic - Next topic

mogli

hi!

i implemented to version to run as an applet. first one uses open-hardware-renderer and second one the software-renderer.
ok, that works greate.

problem is that the heap space is typically limited to 96MB.
after loading the textures and some parts of the world free space is very critical and added a function that removes parts of the world which are invisible (as application i still set them invisible and it works also). ok, that's not the problem as the case may be could be better if i could set them also in applet invisible. but in this place the user has to change the settings for reserved space for applets himself.

but the biggest problem is reloading the applet without restarting the browser.
i set destroy and stop function to free used space but it don't work.
destroy() function looks like


texMan.flush();
Object3D.resetNextID();
stop();
super.destroy();


and stop()

if(loopThread == null){
 loopThread.destroy();
 loopThread = null;
}

exit = true;


after the (!exit)- loop ( ;) ) in mainloop()
i set the following
world.removeAll();
world = null;


and destroy in opengl-mode the key- and mousemapper

but then i reload the page or get page back and return the applet begins to start...first with adding the textures to texmanager...but then it stops with the error memoryoutofspace: java heap space...

what could be wrong with this?
i test to clear cache and restart it but the same mistake. when i restart the browser i can start it normally. i also tested it by calling the carbage collection (System.gc()) at the end but also without any changes...

could be very nice if someone could help me because the hand over for the applet is in a few days  :?

Uija

if(loopThread == null){
 loopThread.destroy();
 loopThread = null;
}

why do you destroy an object that is null?
Copy&Paste error, or did you missed a ! there?

mogli

...oh too bad! i believe i'm such a silly idiot. this should is the problem. have to test it this evening.
sorry, i'm a little bit under pressure...to finish my diploma ;)

raft

hello,

a few days ago i've profiled karga and let me share what i found about memory concerns:

world.removeAll();
world = null;

unfortunately this code piece doesnt effectively retrieves heap back :/ Object3D has a package public field called myWorld referencing its world and world.removeAll() doesnt clear this field. so if you have a reference to any of the objects of your old world, that means you still hold a reference to your world :/

worse enough nulling all of your references to Object3D's and your world and callling System.gc() does not instantly retrieves heap back. if you carefully cleared all references, after some time jvm will correctly garbage collect your world but not instantly.

i suspect this is due to garbage collection mechanism: for instance if object A has a reference to object B, and object B has a reference to object A, and these two arent referenced by any other objects, jvm will eventually garbage collect the two. but i guess it takes some time for garbabe collector to detect the situation

btw, upcoming jPCT version (1.12) has an improved Mesh.compress() method which almost reduces memory requirements to half ;) it may help you a lot

you may also consider using java web start instead of applet. jws is much more flexible than applet and also allows setting max heap size even for untrusted applications

hope this helps
r a f t

EgonOlsen

Quote from: "raft"Object3D has a package public field called myWorld referencing its world and world.removeAll() doesnt clear this field. so if you have a reference to any of the objects of your old world, that means you still hold a reference to your world :/
Ah, that nasty reference...i was never really happy with it, but now it's here to stay... :wink: I'll modify the remove-methods in World to take care of it.