Commits

Anonymous committed 4acf398

- CanvasManager reuse canvas element on IE
- Remove emptyForce whene elements created using document.createElement and gcCollect them

  • Participants
  • Parent commits c61569c

Comments (0)

Files changed (10)

File src/jqplot.axisTickRenderer.js

         if (Number(this.label)) {
             style['whitSpace'] = 'nowrap';
         }
-        
-        // Memory Leaks patch
-        if (this._elem) {
-            this._elem.emptyForce();
-            this._elem = null;
-        }
 
         this._elem = $(document.createElement('div'));
         this._elem.addClass("jqplot-"+this.axis+"-tick");

File src/jqplot.core.js

       }
     };
 
+    // Memory Leaks patch : garbage collector
+    $.gcInit = function() {
+      var gc = $("<div id='gc_jqPlotSalsaGarbage' style='display:none;visibility:hidden;'></div>");
+      $("body").append(gc)
+      $._gc = gc;
+    };
+
+    $.gcCollect = function(elem) {
+      $._gc.append(elem);
+    };
+    
+    $.gcClear = function() {
+      if ($.browser.msie) {
+        $._gc.children().each(function() {
+          this.outerHTML = "";
+        });
+      }
+      
+      $._gc.empty();
+    };
+    
+    $(document).ready(function() {
+      $.gcInit();
+    });
 
     /**
      * Namespace: $.jqplot
             var canvas;
             var makeNew = true;
             
-            if (!$.jqplot.use_excanvas) {
+            // if (!$.jqplot.use_excanvas) { -- Memory Leaks patch: in IE the DOM element canvas still exists, reuse it.
                 for (var i = 0, l = $.jqplot.CanvasManager.canvases.length; i < l; i++) {
                     if ($.jqplot.CanvasManager.free[i] === true) {
                         makeNew = false;
                         break;
                     }
                 }
-            }
+            // }
 
             if (makeNew) {
                 canvas = document.createElement('canvas');
             if ($.jqplot.use_excanvas && window.G_vmlCanvasManager.uninitElement !== undefined) {
                 // excanvas can't be reused, but properly unset
                 window.G_vmlCanvasManager.uninitElement($.jqplot.CanvasManager.canvases[idx]);
-                $.jqplot.CanvasManager.canvases[idx] = null;
+                // $.jqplot.CanvasManager.canvases[idx] = null; -- Memory Leaks patch: in IE the DOM element canvas still exists, reuse it.
+                $.jqplot.CanvasManager.free[idx] = true;
             } 
             else {
                 var canvas = $.jqplot.CanvasManager.canvases[idx];
                     if ($.jqplot.use_excanvas && window.G_vmlCanvasManager.uninitElement !== undefined) {
                       window.G_vmlCanvasManager.uninitElement(el.get(0));
                     }
-                    el.emptyForce();
                     el = null;
-                    t._elem = null;
+                    t[i]._elem = null;
                   }
                 }
                 t = null;
             
             if (clear) {
                 this.canvasManager.freeAllCanvases();
+
                 // Memory Leaks patch
-                // this.target.find("table.jqplot-table-legend,table.jqplot-legend").each( function() {
-                //     $(this).unbind();
+                this.target.find("table.jqplot-table-legend,table.jqplot-legend").each( function() {
+                    $(this).unbind();
 
-                //     $(this).find(".jqplot-seriesToggle").each( function() {
-                //         $(this).unbind();
-                //     });
-                //     $.gcCollect(this);
-                // });
+                    $(this).find(".jqplot-seriesToggle").each( function() {
+                        $(this).unbind();
+                    });
+                    $.gcCollect(this);
+                });
                 
-                // this.target.find(".jqplot-title").each( function() {
-                //     $(this).unbind();
-                //     $.gcCollect(this);
-                // });
+                this.target.find(".jqplot-axis").each( function() {
+                    $(this).unbind();
+                    $.gcCollect(this);
+                });
                 
-                // $.gcClear();
+                this.target.find(".jqplot-title").each( function() {
+                    $(this).unbind();
+                    $.gcCollect(this);
+                });
 
+                this.target.find(".jqplot-cursor-tooltip").each( function() {
+                    $(this).unbind();
+                    $.gcCollect(this);
+                });
+
+                this.target.find(".jqplot-point-label").each( function() {
+                    $(this).unbind();
+                    $.gcCollect(this);
+                });
+
+                $.gcClear();
+                
                 if (this.eventCanvas && this.eventCanvas._elem) {
                     this.eventCanvas._elem.unbind();
                 }

File src/jqplot.divTitleRenderer.js

     };
     
     $.jqplot.DivTitleRenderer.prototype.draw = function() {
-        // Memory Leaks patch
-        if (this._elem) {
-            this._elem.emptyForce();
-            this._elem = null;
-        }
-
         var r = this.renderer;
         var elem = document.createElement('div');
         this._elem = $(elem);

File src/jqplot.linearAxisRenderer.js

             // position it and the labels correctly on the plot.
             var dim=0;
             var temp;
-            // Added for theming.
-            if (this._elem) {
-                // Memory Leaks patch
-                //this._elem.empty();
-                this._elem.emptyForce();
-                this._elem = null;
-            }
-            
+
             this._elem = $(document.createElement('div'));
             this._elem.addClass('jqplot-axis jqplot-'+this.name);
             this._elem.css('position', 'absolute');

File src/jqplot.tableLegendRenderer.js

     
     // called with scope of legend
     $.jqplot.TableLegendRenderer.prototype.draw = function() {
-        if (this._elem) {
-            this._elem.emptyForce();
-            this._elem = null;
-        }
-
         if (this.show) {
             var series = this._series;
             // make a table.  one line label per row.

File src/plugins/jqplot.canvasAxisLabelRenderer.js

               if ($.jqplot.use_excanvas && window.G_vmlCanvasManager.uninitElement !== undefined) {
                   window.G_vmlCanvasManager.uninitElement(this._elem.get(0));
               }
-            
-              this._elem.emptyForce();
+
               this._elem = null;
           }
 

File src/plugins/jqplot.cursor.js

             c.cursorCanvas.resetCanvas();
             c.cursorCanvas = null;
         }
-        
-        if (c._tooltipElem) {
-            c._tooltipElem.emptyForce();
-            c._tooltipElem = null;
-        }
 
-        
         if (c.zoom) {
             c.zoomCanvas = new $.jqplot.GenericCanvas();
             this.eventCanvas._elem.before(c.zoomCanvas.createElement(this._gridPadding, 'jqplot-zoom-canvas', this._plotDimensions, this));
     // called in context of a Legend
     $.jqplot.CursorLegendRenderer.prototype.draw = function() {
         if (this._elem) {
-            this._elem.emptyForce();
             this._elem = null;
         }
         if (this.show) {

File src/plugins/jqplot.highlighter.js

         }
 
         if (this.plugins.highlighter && this.plugins.highlighter._tooltipElem) {
-            this.plugins.highlighter._tooltipElem.emptyForce();
             this.plugins.highlighter._tooltipElem = null;
         }
 

File src/plugins/jqplot.pointLabels.js

         // remove any previous labels
         for (var i=0; i<p._elems.length; i++) {
             // Memory Leaks patch
-            // p._elems[i].remove();
-            p._elems[i].emptyForce();
             p._elems[i] = null;
         }
         p._elems.splice(0, p._elems.length);

File src/plugins/jqplot.pyramidAxisRenderer.js

             var dim=0;
             var temp;
             // Added for theming.
-            if (this._elem) {
-                // Memory Leaks patch
-                //this._elem.empty();
-                this._elem.emptyForce();
-                this._elem = null;
-            }
             
             this._elem = $(document.createElement('div'));
             this._elem.addClass('jqplot-axis jqplot-'+this.name);