Kasparian, Raffi J. wrote:

Hi Kelvin,



Happy New Year!



I started writing this as a general rant to the Java3D community but
you have earned my respect because of your responses to my own
questions and programming issues in the past. So I'm sending this
email to you. I assume that you are already aware of the issues it
addresses. Please reply directly to this issue either in an email to
me or an email to the Java3D community.



I have been working with several heap-crawlers looking for memory
leaks in my Java3D program. I find many instances of Java3D classes
with names like xxxRetained that hold references to objects that would
otherwise be freed. BranchGroupRetained, Shape3DRetained,
BehaviorRetained etc. These retained classes accumulate through the
course of my program leading to an OutOfMemoryError. Increasing the
amount of memory allocated to Java is not a fix. It's just a cop-out
and only delays the inevitable. While I can minimize the references
that these retained classes themselves have, the problem remains are
there are memory leaks in Java3D itself. At its basic level my program
is a scenegraph creator and editor. It is expected that the user will
create and destroy Groups, Geometries, Behaviors etc ever and over
again through interaction with the GUI until he has settled on a
scenegraph that he likes. The leakages occur, of course, when
scenegraph references that my program creates and then removes still
linger in the bowels of Java3D. They happen whether or not I compile
my BranchGroups. I am particularly bothered by Shape3DRetained
instances that still show up in my Canvas3D (!), but the problem is
more general than that.

It is a bug if the BranchGroup remove but Node such as Shape3D under it
is still reference by Java3D.
However if user program has a reference to Node then the NodeRetained
reference will not free.

We've done lots of work to reclaim the memory use by remove BranchGroup.
However there may be
case that we are still missing. Currently we're looking at

bug 4794994 - Memory leak when SharedGroup removed
On the JDK side, there is a bug about applet
4766280 -Memory leak when reloading applet


some memory leak bug address in J3D v1.3.1beta1 are:
4742720 - Memory leak when non-byRef ImageComponent is used for Raster
4748837 - Memory leak when new texture is set in Appearance

I expect the following of Java3D:



When I remove a subgraph from my scenegraph and let go of all my
references to it, all Java3D objects that had bearing only on the
removed subgraph and to which I have no references will become
eligible for garbage collection. Since the user of the Java3D API
doesn't have access to many of the Java3D resources, it is incumbent
on Java3D to manage its own resources better.



At the very least, the Java3D API should provide a method such as
VirtualUniverse.gc() that the programmer could call that would search
through Java3D resources and free unneeded ones.



Note that it is user program responsiblity not to reference any Node in
the  subtree that is remove. A single
Shape3D cache by user program may cause a bundle of scenegraph nodes not
able to GC.  Some other common
error is user application (or AWT/Swing) has reference to Canvas3D or
View so the whole scenegraph is not
GC.  A new  method cleanup() is added in SimpleUnivesrse to help this:


   /**
    * Cleanup memory use and reference by SimpleUniverse.
    * Typically it should be invoked by the applet's destroy method.
    */
   public void cleanup() {
   viewer[0].getView().removeAllCanvas3Ds();
       viewer[0].setViewingPlatform(null);
   removeAllLocales();
   // viewerMap cleanup here to prevent memory leak problem. This is
new in v1.3.1 beta1
   Viewer.clearViewerMap();

   }

If you have particular test program that leak memory in v1.3.1 beta1
please send to us
for investigate.

Thanks.

- Kelvin
------------
Java 3D Team
Sun Microsystems Inc.

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to