Quantcast
Viewing all articles
Browse latest Browse all 82132

DOM elements not getting destroyed? Memory keeps rising....

First off; thanks for the amazing plugin. Your work is much appreciated...

I've been tearing my hair out trying to figure out why the memory usage of my page keep climbing into perpetuity every time I use fnreloadjax to refresh the contents of my datatable. Memory keeps climbing until eventually the page shows the "he's dead jim!" message in Chrome (usually after about a full day and swelling to 1 GB+ of memory usage). I'd assume this is because DOM elements aren't getting destroyed properly... or something? Anything you can do to even point me in the right direction would be sincerely appreciated....

Here's the code for the table initialization:

 var oTable = $('#internalnotes').dataTable( {
    					"bJQueryUI": true,
	  "bPaginate": false,
	  "bDestroy": true,
	  "bDeferRender": true,
		"aaSorting": [[ 2, "desc" ]],
	
	
		"aoColumns": [
		   { "sType": "numeric", "bSearchable": false,
			                 "bVisible":    false },
			{ "iDataSort": 0, sClass: "alignCenter",  "sWidth": "10%" },
			{ "sType": "date", "sWidth": "15%", "bVisible":    false    },
			 { type: "select", values: [ 'Dept1', 'Dept2', 'Dept3'], sClass: "alignCenter",  "sWidth": "10%"  },
			{"sClass": "alignLeft", "sWidth": "70%" },

		],
		
		"sAjaxSource": "GetNewNotes.php?CustomTickers=<?php echo $CustomTickers . "&username=" . $username . "&usertype=" . $usertype?>"
		
		
    } )
	
	.columnFilter({
	
			aoColumns: [ 
			null,
			null,
			null,
			 { type: "select", values: [ 'Dept1', 'Dept2', 'Dept3', 'Dept4']  },
			null
					
				]
				
		});


and here is the code that goes within a repeating setTimeout function (loads every 20 seconds) to get the new content (it has some extra code for deciding whether or not to show a notification -- i.e. if a new item has been added)

 

var NoteItemCountPre = 0;
var NoteItemCountPost = 0;

  
$.fn.dataTableExt.oApi.fnReloadAjax = function ( oSettings, sNewSource, fnCallback, bStandingRedraw )
{
 
NoteItemCountPost = oTable.fnGetData().length;

 if ( typeof sNewSource != 'undefined' && sNewSource != null ) {
        oSettings.sAjaxSource = sNewSource;
    }
 
    // Server-side processing should just call fnDraw
    if ( oSettings.oFeatures.bServerSide ) {
        this.fnDraw();
        return;
    }
 
    this.oApi._fnProcessingDisplay( oSettings, true );
    var that = this;
    var iStart = oSettings._iDisplayStart;
    var aData = [];
  
    this.oApi._fnServerParams( oSettings, aData );
      
    oSettings.fnServerData.call( oSettings.oInstance, oSettings.sAjaxSource, aData, function(json) {

		/* Clear the old information from the table */
        that.oApi._fnClearTable( oSettings );
          
        /* Got the data - add it to the table */
        var aData =  (oSettings.sAjaxDataProp !== "") ?
            that.oApi._fnGetObjectDataFn( oSettings.sAjaxDataProp )( json ) : json;

		var NoteItemCountPre = 0;
		
        for ( var i=0 ; i<aData.length ; i++ )
        {
            that.oApi._fnAddData( oSettings, aData[i] );
			
			NoteItemCountPre++;

        }

	    if (NoteItemCountPre > NoteItemCountPost)

		{

		
		ShowNotification();
		
		$.titleAlert('New Blog Post', {interval:1000, originalTitleInterval:200});

		}
          
        oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
          
        if ( typeof bStandingRedraw != 'undefined' && bStandingRedraw === true )
        {
            oSettings._iDisplayStart = iStart;
            that.fnDraw( false );
        }
        else
        {
            that.fnDraw();
        }
          
        that.oApi._fnProcessingDisplay( oSettings, false );
          
        /* Callback user function - for event handlers etc */
        if ( typeof fnCallback == 'function' && fnCallback != null )
        {
            fnCallback( oSettings );
        }
    }, oSettings );

	};

var NoteItemCountPost = NoteItemCountPre; 



this is what the setTimeout function looks like:


var reloadNotes = function(){



clearTimeout(timeoutId);


			
oTable.fnReloadAjax( 'GetNewNotes.php?CustomTickers=<?php echo $CustomTickers ?>&username=<?php echo $username ?>&usertype=<?php echo $usertype ?>');
	

startCountdown(); // Otherwise it will just run once



	};



and the countdown that starts the timer

var timeoutId = 0;

function startCountdown() {
   
 
   
   clearTimeout(timeoutId)

   timeoutId = setTimeout(reloadNotes, 20000); 
   
  
   
};



Viewing all articles
Browse latest Browse all 82132

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>