aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKevin Rushforth <[email protected]>2006-10-20 18:06:17 +0000
committerKevin Rushforth <[email protected]>2006-10-20 18:06:17 +0000
commitc5532f5f8f8b9fe5d4da8ecc5194ec1f864edd23 (patch)
treef0451f9e50155f1f2af4a46d6e7f09d282eddcc7 /src
parentdf863b1f8aa929ab70e6cb7d8f7861eb55af4bad (diff)
Fixed issue 353: GeometryArray Memory Leak
git-svn-id: https://svn.java.net/svn/j3d-core~svn/trunk@723 ba19aa83-45c5-6ac9-afd3-db810772062c
Diffstat (limited to 'src')
-rw-r--r--src/classes/share/javax/media/j3d/BHTree.java9
-rw-r--r--src/classes/share/javax/media/j3d/GeometryStructure.java58
-rw-r--r--src/classes/share/javax/media/j3d/RenderBin.java9
3 files changed, 52 insertions, 24 deletions
diff --git a/src/classes/share/javax/media/j3d/BHTree.java b/src/classes/share/javax/media/j3d/BHTree.java
index 3d53667..6ec6f6a 100644
--- a/src/classes/share/javax/media/j3d/BHTree.java
+++ b/src/classes/share/javax/media/j3d/BHTree.java
@@ -19,10 +19,10 @@ import javax.vecmath.Point4d;
class BHTree {
Locale locale;
- BHNode root;
- BHInsertStructure insertStructure = null;
-
+ private BHNode root;
+ private BHInsertStructure insertStructure = null;
+
// Temporary point, so we dont generate garbage
Point4d tPoint4d = new Point4d();
@@ -700,6 +700,9 @@ class BHTree {
insertStructure.updateBoundingTree(this);
// System.out.println("BHTree - Inserting ...");
+
+ // Issue 353: clear temporary insertStructure so we don't leak.
+ insertStructure.clear();
// Guard against size<1 is done at the start of this method.
estMaxDepth += (int) (Math.log(size)/LOG_OF_2) + 1;
diff --git a/src/classes/share/javax/media/j3d/GeometryStructure.java b/src/classes/share/javax/media/j3d/GeometryStructure.java
index bddfac0..23ea7ee 100644
--- a/src/classes/share/javax/media/j3d/GeometryStructure.java
+++ b/src/classes/share/javax/media/j3d/GeometryStructure.java
@@ -252,7 +252,14 @@ class GeometryStructure extends J3dStructure {
}
private void clearBhNodeArr() {
- bhNodeCount = 0;
+ // Issue 353: set all elements to null so we don't leak
+ // NOTE: we really should change this to be an ArrayList, but that
+ // would be a less localized change. Consider for 1.6.0.
+ for (int i = 0; i < bhNodeCount; i++) {
+ bhNodeArr[i] = null;
+ }
+
+ bhNodeCount = 0;
}
private void addToBhNodeArr(BHNode bhNode) {
@@ -291,7 +298,7 @@ class GeometryStructure extends J3dStructure {
Object node;
GeometryAtom geomAtom;
BHTree currTree = null;
-
+
clearBhNodeArr();
// System.out.println("GS : nodes.length is " + nodes.length);
@@ -340,7 +347,10 @@ class GeometryStructure extends J3dStructure {
}
currTree.insert(bhNodeArr, bhNodeCount);
-
+
+ // Issue 353: must clear array after we are done with it
+ clearBhNodeArr();
+
// currTree.gatherTreeStatistics();
}
@@ -351,6 +361,7 @@ class GeometryStructure extends J3dStructure {
int index;
clearBhNodeArr();
+
for (int i=0; i<nodes.length; i++) {
node = nodes[i];
if (node instanceof GeometryAtom) {
@@ -421,15 +432,21 @@ class GeometryStructure extends J3dStructure {
if (currTree == null) {
index = getBHTreeIndex(((BHLeafNode)bhNodeArr[0]).getLocale());
- if (index<0)
+ if (index<0) {
+ // Issue 353: must clear array after we are done with it
+ clearBhNodeArr();
+
return;
+ }
currTree = bhTreeArr[index];
}
currTree.delete(bhNodeArr, bhNodeCount);
-
- // It is safe to do it here since only GeometryStructure
- // thread invoke wakeupOnCollisionEntry/Exit .toArray()
+ // Issue 353: must clear array after we are done with it
+ clearBhNodeArr();
+
+ // It is safe to do it here since only GeometryStructure
+ // thread invoke wakeupOnCollisionEntry/Exit .toArray()
wakeupOnCollisionEntry.clearMirror();
wakeupOnCollisionMovement.clearMirror();
@@ -447,7 +464,8 @@ class GeometryStructure extends J3dStructure {
int index;
Object node;
- clearBhNodeArr();
+ clearBhNodeArr();
+
for (int i = 0; i < nodes.length; i++) {
node = nodes[i];
if (node instanceof GeometryAtom) {
@@ -478,10 +496,13 @@ class GeometryStructure extends J3dStructure {
index = getBHTreeIndex(((BHLeafNode)bhNodeArr[0]).getLocale());
if (index >= 0) {
- bhTreeArr[index].boundsChanged(bhNodeArr, bhNodeCount);
-
+ bhTreeArr[index].boundsChanged(bhNodeArr, bhNodeCount);
}
- }
+
+ // Issue 353: must clear array after we are done with it
+ clearBhNodeArr();
+
+ }
private void processTransformChanged(UpdateTargets targets) {
@@ -490,8 +511,8 @@ class GeometryStructure extends J3dStructure {
UnorderList arrList;
int size;
- clearBhNodeArr();
-
+ clearBhNodeArr();
+
arrList = targets.targetList[Targets.GEO_TARGETS];
if (arrList != null) {
@@ -541,6 +562,10 @@ class GeometryStructure extends J3dStructure {
bhTreeArr[index].boundsChanged(bhNodeArr, bhNodeCount);
}
+
+ // Issue 353: must clear array after we are done with it
+ clearBhNodeArr();
+
}
// This method is called by RenderBin to get a array of possibly visible
@@ -548,7 +573,7 @@ class GeometryStructure extends J3dStructure {
// bhTrees mustn't be null.
// Return true if bhTree's root in encompass by frustumBBox.
- boolean getVisibleBHTrees(RenderBin rBin, ArrayList bhTrees,
+ boolean getVisibleBHTrees(RenderBin rBin,
BoundingBox frustumBBox,
Locale locale, long referenceTime,
boolean stateChanged,
@@ -560,7 +585,10 @@ class GeometryStructure extends J3dStructure {
// System.out.println("GeometryStructure : view's locale is " + locale);
lock.readLock();
- bhTrees.clear();
+ // Issue 353: create a new array list each time rather than passing it
+ // in. This will not generate too much garbage, since we only call
+ // this once per frame and it is very short-lived.
+ ArrayList bhTrees = new ArrayList();
if (bhTreeCount == 1) {
// For debugging only.
if (J3dDebug.devPhase) {
diff --git a/src/classes/share/javax/media/j3d/RenderBin.java b/src/classes/share/javax/media/j3d/RenderBin.java
index 138d458..03d510c 100644
--- a/src/classes/share/javax/media/j3d/RenderBin.java
+++ b/src/classes/share/javax/media/j3d/RenderBin.java
@@ -31,9 +31,7 @@ class RenderBin extends J3dStructure implements ObjectUpdate {
* A couple ArrayLists used during light Processing
*/
ArrayList lightMessageList = new ArrayList(5);
-
- ArrayList bhTreesArrList = new ArrayList(5);
-
+
// Messges retrieved when a message is sent to RenderingEnv Structure
J3dMessage[] m;
@@ -1783,13 +1781,13 @@ class RenderBin extends J3dStructure implements ObjectUpdate {
ViewPlatform vp = view.getViewPlatform();
if (vp != null) {
allEnComp = universe.geometryStructure.
- getVisibleBHTrees(this, bhTreesArrList, viewFrustumBBox,
+ getVisibleBHTrees(this, viewFrustumBBox,
locale, referenceTime,
visGAIsDirty || reactivateView || localeChanged ||
((view.viewCache.vcDirtyMask &
View.VISIBILITY_POLICY_DIRTY) != 0),
view.viewCache.visibilityPolicy);
-
+
reactivateView = false;
// process background geometry atoms
if (currentActiveBackground != null &&
@@ -5927,7 +5925,6 @@ System.out.println("......tb.soleUser= " +
bgOrderedBins.clear();
nodeComponentList.clear();
orientedRAs.clear();
- bhTreesArrList.clear();
// clean up any messages that are queued up, since they are
// irrelevant