3.2.0

Help with memory leak

I have built a grid swiss army knife by assembling code found on the forum (thanks to all). The problem is, I have managed to create a fairly major memory leak. With 125k of data, 10 page refreshes it leaks about 2mb. The meat of what I am doing is in the code below.

Any help would be appreciated.

<html>
<head>
  <!-- global grid template 4/14/2005 kg -->
  <!-- ActiveWidgets stylesheet and scripts -->
  <link href="/javascript/activewidgets/runtime/styles/xp/grid.css" rel="stylesheet" type="text/css" ></link>
  <script src="/javascript/activewidgets/runtime/lib/grid.js"></script>

  <link href="/css/module_grid.css" rel="stylesheet" type="text/css" id='gridLayout'></link>

  <script type="text/javascript">
    var sessionid = "m42e65a9a54a8c0.40068292";
    var module = "contacts";
    var filter = "keywords=&folder=clients&lastname=&firstname=&view=default";
    var gridUrlBase = module + "_grid_data.php?sessionid=" + sessionid;

    var myColumns = [
        " ","Name","Company","Phone","Email"
      ];
    var myColWidths = [
        30,150,150,100,170
      ];

    try {

      var table = new Active.Text.Table;

    // todo - allow grid_data to send back field titles in data row 0 and
    // field lenghts in data row 1 to make the table self configuring

      table.response = function(text) {
        var i, s, rows = []
        if (text.substr(0,5).toLowerCase() == 'error') {
          alert(text);
        }
        else {
          a = text.split(/\r*\n/);
          for (i=0; i<a.length; i++) {
            if (a[i]) {
              rows[i] = a[i].split("|")
            }
          }
        }
        this._data = rows;
        Active.HTTP.Request.prototype.response.call(this);
      };

      //  create ActiveWidgets Grid javascript object
      var obj = new Active.Controls.Grid;

      //  set number of rows/columns
      obj.setColumnProperty("count", myColumns.length);
      obj.setProperty("column/count", myColumns.length);

      obj._freshData = true;
      obj.setModel("data", table);

      var _refresh = obj.refresh;

      obj.refresh = function(){

        var scrollbars = this.getTemplate("layout").getContent("scrollbars");
        var data = this.getTemplate("layout").getContent("data");
        var top = this.getTemplate("layout").getContent("top");
        var left = this.getTemplate("layout").getContent("left");

        var x = scrollbars.element().scrollLeft;
        var y = scrollbars.element().scrollTop;
        if (x==0 && y==0){
          _refresh.call(this);
        }
        else {
          var _obj = this;
          _obj.element().runtimeStyle.visibility = "hidden";
          _refresh.call(this);


          window.setTimeout(function(){
            scrollbars.element().scrollLeft = x;
            scrollbars.element().scrollTop = y;
            data.element().scrollLeft = x;
            data.element().scrollTop = y;
            top.element().scrollLeft = x;
            left.element().scrollTop = y;
            _obj.element().runtimeStyle.visibility = "visible";

    //        _obj.element().focus();
          }, 0 );
        }
      } 

      obj.setColumnProperty("text", function(i){return myColumns[i]});

      //  set headers width/height
      obj.setRowHeaderWidth("28px");
      obj.setColumnHeaderHeight("20px");

      obj.setSelectionMultiple(false);

      var alternate = function(){
          return this.getProperty("row/order") % 2 ? "#dfdfdf" : "#ffffff";
        }

      var row = new Active.Templates.Row;
      row.setStyle("background", alternate);
      row.setEvent("onmouseover", "mouseover(this, 'active-row-highlight')");
      row.setEvent("onmouseout", "mouseout(this, 'active-row-highlight')");
      obj.setTemplate("row", row);


      obj.setColumnProperty("count", myColumns.length);
      obj.setProperty("column/count", myColumns.length);

      if (document.getElementById("gridLayout").sheet)
      {
        if (document.getElementById("gridLayout").sheet.rules)
          theRules = document.getElementById("gridLayout").sheet.rules;
        else if (document.getElementById("gridLayout").sheet.cssRules)
          theRules = document.getElementById("gridLayout").sheet.cssRules;
      }
      else if (document.getElementById("gridLayout").styleSheet)
      {
        if (document.getElementById("gridLayout").styleSheet.cssRules)
          theRules = document.getElementById("gridLayout").syleSheet.cssRules;
        else if (document.getElementById("gridLayout").styleSheet.rules)
          theRules = document.getElementById("gridLayout").styleSheet.rules;
      }

      var currentColumn=0;
      for( cs=0;cs<theRules.length-1;cs++) {  
        if (theRules[cs].selectorText == ".active-column-"+currentColumn) {
          theRules[cs].style.width = myColWidths[currentColumn]+'px';
          currentColumn++; 
        }
// IE chokes on the currentColumn++ above if the next line is changed to > rather than ==
// this drove me #$%*ing nuts for 2 hours  
        if (currentColumn == myColumns.length)
        {
          break;
        }
      }

      obj.getTemplate("layout").action("adjustSize");

      if (filter.length > 0) {
        table.setProperty("URL", gridUrlBase + '&' + filter);
      }
      else {
        table.setProperty("URL", gridUrlBase);
      }

      table.request();

    }
    catch(e){
    }
  </script>

</head>
<body>
  <script type="text/javascript">
    document.write(obj);
  </script>
</body>
</html>


Would be glad to share what I am doing on the server side if needed or if anyone is interested.
Ken Gregg
July 27,
Forgot to mention Browser is Firefox 1.0 have not tried it with IE.
Ken Gregg
July 27,

This topic is archived.

See also:


Back to support forum