From 784e8b50a760d1f9900dbcb1311cb9aa1bb5a28b Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Thu, 29 Jan 2015 20:37:28 -0500
Subject: [PATCH] deallocation stuff

---
 js/fea/dmaCell.js    | 20 +++++++++++---------
 js/fea/dmaPart.js    | 13 +++++++++----
 js/models/lattice.js |  6 ++++--
 3 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/js/fea/dmaCell.js b/js/fea/dmaCell.js
index 7c988a2c..7ff26b32 100644
--- a/js/fea/dmaCell.js
+++ b/js/fea/dmaCell.js
@@ -145,19 +145,21 @@
          return this.scale;//I don't like this stored here
      };
 
-    DMACell.prototype.remove = function(){
-        if (this.cellMesh) window.three.sceneRemove(this.cellMesh);
-        _.each(this.parts, function(part){
-            part.remove();
-        });
-        this.destroy();
-    };
-
     DMACell.prototype.destroy = function(){
-        if (this.cellMesh) this.cellMesh.myCell = null;
+        if (this.cellMesh) {
+            window.three.sceneRemove(this.cellMesh);
+            this.cellMesh.myCell = null;
+            this.cellMesh.dispose();
+//            geometry.dispose();
+//            material.dispose();
+            this.cellMesh = null;
+        }
         _.each(this.parts, function(part){
             part.destroy();
         });
+        this.indices = null;
+        this.scale = null;
+        this.position = null;
         this.parts = null;
     };
 
diff --git a/js/fea/dmaPart.js b/js/fea/dmaPart.js
index 865ae6f9..a28c86e4 100644
--- a/js/fea/dmaPart.js
+++ b/js/fea/dmaPart.js
@@ -91,12 +91,17 @@
         if (this.mesh) this.mesh.visible = false;
     };
 
-    DMAPart.prototype.remove = function(){
-        if (this.mesh) window.three.sceneRemove(this.mesh);
-    };
-
     DMAPart.prototype.destroy = function(){
+        if (this.mesh) {
+            window.three.sceneRemove(this.mesh);
+            this.mesh.dispose();
+//            geometry.dispose();
+//            material.dispose();
+            this.mesh = null;
+        }
         this.parentCell = null;
+        this.oddZFlag = null;
+        this.type = null;
     };
 
     self.DMAPart =  DMAPart;
diff --git a/js/models/lattice.js b/js/models/lattice.js
index 9ea75162..b184cc08 100644
--- a/js/models/lattice.js
+++ b/js/models/lattice.js
@@ -154,8 +154,8 @@ Lattice = Backbone.Model.extend({
         var cell = object.parent.myCell;
         var index = this._subtract(cell.indices, this.get("cellsMin"));
         var cells = this.get("cells");
+        cell.destroy();
         cells[index.x][index.y][index.z] = null;
-        cell.remove();
 
         //todo shrink cells matrix if needed
 
@@ -165,9 +165,11 @@ Lattice = Backbone.Model.extend({
 
     clearCells: function(){
         this._iterCells(this.get("cells"), function(cell){
-            if (cell) cell.remove();
+            if (cell) cell.destroy();
         });
         this.set("cells", this.defaults.cells);
+        this.set("cellsMax", this.defaults.cellsMax);
+        this.set("cellsMin", this.defaults.cellsMin);
         this.set("numCells", 0);
         window.three.render();
     },
-- 
GitLab