Author Topic: Memory leak on refreshDataAndView ?  (Read 2824 times)

mond2000

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 2
    • View Profile
Memory leak on refreshDataAndView ?
« on: February 07, 2016, 03:04:31 am »
Dear Sir,

I noticed, that the memory usage is increased on each call of refreshDataAndView or even refresh,

below, a sample code,
Thank you for your help.




/***************************/

<html>
    <head>
    <title>test</title>
   
   
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/themes/base/jquery-ui.css" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>   
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
   
    <!--PQ Grid files-->
    <link href="Lib/ParamQueryProVersion/pqgrid.min.css" rel="stylesheet" />
    <script src="Lib/ParamQueryProVersion/pqgrid.min.js"></script>

</head>
    <body style="overflow:auto; margin-left:0px;margin-top:0px;" id ="test"  >
    <div id="grid_array" style="margin:auto;"></div>

    <script>
        var data = [
            [1, 'Line 0','0'],
            [2, 'line 1','1'],
       [3, 'line 2','2']
         ];

        var obj = { width: 700, height: 300,  title: "Grid From Array",   numberCell:{resizable:true, title: "#"},
            editable: false,  scrollModel: { autoFit: true },  flexWidth: true,  showBottom:false,  resizable: true  };
       
        obj.colModel = [
            { title: "Rank", width: 100, dataType: "integer" },
            { title: "Line", width: 200, dataType: "string" },
            { title: "Num", width: 200, dataType: "integer" }
        ];
        obj.dataModel = { data: data };

        var $grid = $("#grid_array").pqGrid(obj);
        var k = 0;
       
        function Upd_Grid_1(k) {
            data[2][2] = k;
            $("#grid_array").pqGrid("refreshDataAndView");
           
            k = k + 1;
            setTimeout(function () { Upd_Grid_1(k); }, 10);
        }

        Upd_Grid_1(0);
    </script>
</body>
</html>

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Memory leak on refreshDataAndView ?
« Reply #1 on: February 08, 2016, 09:01:13 am »
ParamQuery grid Pro is proactively tested against memory leaks.

Consumed Memory increases in your test case because it calls refreshDataAndView() in an infinite loop without a pause, which prevents the browser to do garbage collection of dead nodes accumulated in every refresh cycle.

Any refresh* methods are better not to be used in a loop as noted in the API.
« Last Edit: February 08, 2016, 11:08:15 am by paramquery »

mond2000

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Memory leak on refreshDataAndView ?
« Reply #2 on: February 08, 2016, 01:04:50 pm »
Thank you for your reply,
Our application requires an update of six grids each 2 seconds.
Any suggestion to avoid the mentioned problem is welcome.
Thank you for your help.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Memory leak on refreshDataAndView ?
« Reply #3 on: February 08, 2016, 01:50:43 pm »
Since there are six grids that leaves 1/3 second for every grid. It would be helpful to check the data first for changes and do a refresh only when required.


Please follow this:

1) use virtual mode. { virtualX: true, virtualY: true }. The number of nodes and refresh time is less in virtual mode.

2) Try to increase the time interval if possible.

3) use the latest version of pqGrid.
« Last Edit: February 08, 2016, 01:58:23 pm by paramquery »