www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: mogli on August 26, 2006, 05:43:35 pm

Title: problem with applet and heap space
Post by: mogli on August 26, 2006, 05:43:35 pm
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

Code: [Select]

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


and stop()
Code: [Select]

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

exit = true;


after the (!exit)- loop ( ;) ) in mainloop()
i set the following
Code: [Select]

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  :?
Title: problem with applet and heap space
Post by: Uija on August 28, 2006, 10:49:30 am
Code: [Select]
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?
Title: problem with applet and heap space
Post by: mogli on August 28, 2006, 04:14:01 pm
...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 ;)
Title: problem with applet and heap space
Post by: raft on August 29, 2006, 01:15:05 pm
hello,

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

Code: [Select]
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
Code: [Select]
r a f t
Title: problem with applet and heap space
Post by: EgonOlsen on August 29, 2006, 05:39:37 pm
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.