Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Major memory leak in TransformShader  (Read 2604 times)
0 Members and 1 Guest are viewing this topic.
Offline abies

Senior Member





« Posted 2003-11-04 06:31:05 »

For some reason, TransformShader.TransformStateMap is leaking memory. When running one of simple tests with rotating cube, StateMap is fed with transforms, which is ok, but it never get cleaned up. Every frame, few objects get stuck there forever.

As far as I understand, StateMap tries to find StateNode for given transform. As it is not possible when transform has changed in any way, new StateNode is added - and never removed. Of course, with StateNode there is a stale reference to Transform3D, which in turn has a reference to matrix or two... While memory hit is not so bad (but it sums up quite quickly, something like 1MB per minute), I'm afraid that tree performance will get down after some time.

BTW, is there any particular reason to keep Transform nodes in TreeMap ? Do they have to be sorted in this order (seems more or less arbitrary, it is not a distance from viewpoint or something which could be used later) ? I'm afraid, that with more nodes, time used for sorting/checking it will start to take a lot of time.

Artur Biesiadowski
Offline DavidYazel

Junior Member




Java games rock!


« Reply #1 - Posted 2003-11-04 10:47:07 »

Good catch.  I will see what I can do to clean that up.  

David Yazel
Xith3D Project Founder
http://xith3d.dev.java.net

It may look complicated, but in the end it is just a bunch of triangles
Offline Jani Laakso

Junior Member




Do it with Java!


« Reply #2 - Posted 2003-11-18 16:56:19 »

This is causing huge memory leaks. I did a very simple application that constantly rotates and moves 100 cubes on the screen.  It hogs up the memory usage roughly 3 megabytes per second up to a certain point after java gives out of memory error.  I am using Xith3d straight from the CVS.

This is directly related to com.xith3d.scenegraph.setTransform(Transform3D t). The more I call it, the more mem is wasted. I understand abies described exactly the same problem, only better. Same kind of problem lies also on this thread: http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=xith3d;action=display;num=1067755266
(Topic: Argh, memory leak *stabs self in the face*)

Is there any way to go around this problem, or should I patiently wait for the Xith3d experts to fix this problem?


Ps. Thanks for a great 3d library, nice work everyone.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online kevglass

JGO Kernel


Medals: 120
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #3 - Posted 2003-11-18 17:52:20 »

I'm seeming this issue aswell, at least I think I am Smiley

Kev

Offline Jens

Senior Member




Java for games!


« Reply #4 - Posted 2003-11-18 18:41:47 »

I just made a short test: I rotate a model around for quite a long time (half an hour?). The FPS rate went down and the app stopped to work at all (without an error message).

Xith3D Getting Started Guide (PDF,HTML,Source)
Online kevglass

JGO Kernel


Medals: 120
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #5 - Posted 2003-11-22 16:07:59 »

Any news on the memory leak fix for setTransform()?

Kev

Offline DavidYazel

Junior Member




Java games rock!


« Reply #6 - Posted 2003-11-22 16:27:36 »

Thanks for the reminder, I will put this on top of the list.

David Yazel
Xith3D Project Founder
http://xith3d.dev.java.net

It may look complicated, but in the end it is just a bunch of triangles
Online kevglass

JGO Kernel


Medals: 120
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #7 - Posted 2003-11-22 17:19:00 »

Further to this, I got a little bogged down with the problem since it was causing me no end of slow down, and so ..  

It seems to be caused by the generation of loads and loads of StateNodes, all based around Transform3Ds. Now I don't really understand what all this stuff is for. However, I also get a tonne of TreeMap entries showing up on the profile.

I had a look round the code and it seems to be a problem with the StateMap. Now, I can't really tell the implications of the follow but it did at least seem to fix the problem without breaking any of my rendering..

Anyway, introduction over, here's the change I made, thought it might help in finding the real problem..

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
    void assignState( StateTrackable trackable ) {

        StateNode sn = trackable.getStateNode();
        // Commenting out null check will enforce existing StateNode lookup on every shader creation, but this is
       // not a high performance impact because of the atom/shader caching handled now on higher level,
       // and we have to get new (or existing) id on change made
//        if (sn == null) {
           StateNode existing = (StateNode)states.get(trackable);
            if (existing != null) {
                trackable.setStateNode(existing);
            } else {
                sn = new StateNode(trackable);
                sn.id = nextId++;
               
                // took this out and replaced it with the line below, since first it
               // naively seems more logical but also seems to prevent the Transform3D
               // being reproduced over and over
               //states.put(sn.masterCopy,sn);
               states.put(trackable,sn);
               
                trackable.setStateNode(sn);
            }
//        }

    }


Apologies if this turns out to be a red herring so to speak.

Kev

Offline DavidYazel

Junior Member




Java games rock!


« Reply #8 - Posted 2003-11-22 17:36:33 »

While that looks like it would work, it would actually cause some serious problems.  Lets say you have Material A and Material B and they have exactly the same properties.  They would be mapped to the same state.  Now you update Material B. This would update the state, but Material A is mapped to that state, so it gets changed also.

I have solved the trabform leaking problem a different way, the same way I do it with textures, which is to assume that each instance of a transform is unique.  This means that if you had two transforms which were actually the same values we would still change state, but that is probably pretty rare.

David Yazel
Xith3D Project Founder
http://xith3d.dev.java.net

It may look complicated, but in the end it is just a bunch of triangles
Online kevglass

JGO Kernel


Medals: 120
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #9 - Posted 2003-11-22 17:55:19 »

Fantastic!  Grin

Was wondering if I was being a little naive about the whole thing, hence the babbling above.

Is the change available yet?

Kev

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline DavidYazel

Junior Member




Java games rock!


« Reply #10 - Posted 2003-11-22 18:13:45 »

yep it is committed.

David Yazel
Xith3D Project Founder
http://xith3d.dev.java.net

It may look complicated, but in the end it is just a bunch of triangles
Offline Jani Laakso

Junior Member




Do it with Java!


« Reply #11 - Posted 2003-11-23 07:58:33 »

Good work! At least it fixed my application problems.

Now I can share my Xith3d physics demo (it uses Open Dynamics Engine).
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (35 views)
2014-07-24 01:59:36

Riven (35 views)
2014-07-23 21:16:32

Riven (22 views)
2014-07-23 21:07:15

Riven (26 views)
2014-07-23 20:56:16

ctomni231 (56 views)
2014-07-18 06:55:21

Zero Volt (48 views)
2014-07-17 23:47:54

danieldean (39 views)
2014-07-17 23:41:23

MustardPeter (43 views)
2014-07-16 23:30:00

Cero (59 views)
2014-07-16 00:42:17

Riven (56 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!