I have a php application, where I .load() extensive content every 2 minutes into div. The browser (I have to build it for IE8) usually starts to slow down after few minutes of reloading the data. I already know the reason - the memory doesn't get rid of the data loaded previously as long as the page itself is loaded.
Is there any way to do this so that the memory doesn't get flooded after few/many reloads?
I found this:
jQuery load() method memory leak?
and cool answer to it here (see full thread https://stackoverflow.com/a/2180355/3424808):
This isn't a full answer, but I quickly found how to fix all my code with minimal changes. In my "base" js class (this is an object which is used on every page for standard button hookups by class name etc) I added the following method which does the check for dupe handlers:
BindOnce: function(triggerName, fn) {
function handlerExists(triggerName, theHandler) {
function getFunctionName(fn) {
var rgx = /^function\s+([^\(\s]+)/
var matches = rgx.exec(fn.toString());
return matches ? matches[1] : "(anonymous)"
}
exists = false;
var handlerName = getFunctionName(theHandler);
if ($(document).data('events') !== undefined) {
var event = $(document).data('events')[triggerName];
if (event !== undefined) {
$.each(event, function(i, handler) {
if (getFunctionName(handler) == handlerName) {
exists = true;
}
});
}
}
return exists;
}
if (!handlerExists(triggerName, fn)) {
$(document).bind(triggerName, fn);
}
}
Then I just invoke it instead of the bind method!
But I can't get that to work (when I rewrite simple working .bind() fn it stops working). Is therea way to achieve this some other way?
Or could anybody help me with the script I posted? Does nothing when I assign it to button. I use the function like:
$('#myButtonID').BindOnce("click", function() {
alert( "User clicked on 'foo.'" );
});
which works for simple .bind()
EDIT
heres the original .load() thats killing me.
<script type="text/javascript">
var skill = <?php echo json_encode($skill_, JSON_UNESCAPED_UNICODE); ?>;
var skill_final = <?php echo json_encode($skill_final, JSON_UNESCAPED_UNICODE); ?>;
var camp_final = <?php echo json_encode($camp_final, JSON_UNESCAPED_UNICODE); ?>;
var jmeno = <?php echo json_encode($jmeno_, JSON_UNESCAPED_UNICODE); ?>;
var pozice = <?php echo json_encode($pozice_, JSON_UNESCAPED_UNICODE); ?>;
var delka = <?php echo json_encode($delka_, JSON_UNESCAPED_UNICODE); ?>;
var opravneni = <?php echo json_encode($opravneni, JSON_UNESCAPED_UNICODE); ?>;
$(document).ready(function(){
refreshPrehled();
});
function refreshPrehled(){
$('#checkboxes').load('load_prehled.php', {
skill: skill,
skill_final: skill_final,
camp_final: camp_final,
jmeno: jmeno,
pozice: pozice,
delka: delka,
opravneni: opravneni
}, function(){
setInterval(refreshPrehled, 120000);
});
}
</script>