memory leaks
memory leaks
Hi Guys,
Hopefully I’m posting this in the correct spot. I have a problem with memory leaking out of my JQuery. I have inherited an Ajax function that needs to perpetually listen to a xml page that is being updated for a call centre wallboard. Can someone have a second look across this and let me know if there is anything particularly inefficient that you can see.
-
function call_queue() {
//Pre: Function runs onload of DOM, handles XML passed from server, changes state on html page when passed a new state from the server
//Post: recives xml from server, handles output to html, calls the function again
$(document).ready(function() {
$.ajax({
type: "POST",
url: "<<URL to return XML HERE>>",
cache: false,
proxy: "<< HTTP PROXY Here >>",
success: function(xml) {
//-- Check for nightmode --
if($("State", xml).text() == "Nightmode" && is_nightMode == false){
//activate thickbox w nightmode info
tb_show("Night Mode Mobile: "+$("Mobile", xml).text(),"<<image url here>>",null);
//set nightmode variable
is_nightMode = true;
}
if($("State", xml).text() == "Daymode" && is_nightMode == true){
//deactivate nigthmode
tb_remove();
//turn off nightmode
is_nightMode = false;
}
//write out the after hours mobile
$("#Night_Mode_Mobile").html($("Mobile", xml).text());
//-- read in names --
//read agent ready names into an array
var agent_ready_names = $("ReadyAgentList", xml).text();
//read agent talking names into an array
var agent_talking_names = $("TalkingAgentList", xml).text();
var agents_talking_currently = agent_talking_names;
//read agent reserved names into an array
var agent_reserved_names = $("ReservedAgentList", xml).text();
//add a break at the end of each agent name before writing to HTML
agent_talking_names = agent_talking_names.split(";");
agent_ready_names = agent_ready_names.split(";");
agent_reserved_names = agent_reserved_names.split(";");
//-- read in numbers --
//read numbers into integer variables
var N_CallsToday = parseInt($("CallsToday", xml).text());
var N_AgentsReady = parseInt($("AgentsReady", xml).text());
var N_AgentsReserved = parseInt($("AgentsReserved", xml).text());
//---- output xml content to seperate HTML div tags
//-- call waiting timer
if($("LongestWaiting", xml).text() != "0:00:00"){
//show call waiting only when the timer is ticking
$("#N_LongestWaiting").html($("LongestWaiting", xml).text());
//-- CSS event object --
el = document.getElementById('N_LongestWaiting');
el.style.backgroundColor = '#FFFF68';
}
else {
$("#N_LongestWaiting").html("");
//-- CSS event object --
el = document.getElementById('N_LongestWaiting');
el.style.backgroundColor = '#EFF3F9';
}
//-- call waiting counter
if($("CallsWaiting", xml).text() == "0"){
//#A5FF7F
$("#N_CallsWaiting").html("<div id='0_waiting'>");
$("#N_CallsWaiting").append($("CallsWaiting", xml).text());
$("#N_CallsWaiting").append("</div>");
el = document.getElementById('N_CallsWaiting');
el.style.backgroundColor = '#A5FF7F';
}
if($("CallsWaiting", xml).text() == "1"){
//#FFFF68
$("#N_CallsWaiting").html("<div id='1_waiting'>");
$("#N_CallsWaiting").append($("CallsWaiting", xml).text());
$("#N_CallsWaiting").append("</div>");
el = document.getElementById('N_CallsWaiting');
el.style.backgroundColor = '#FFFF68';
}
if($("CallsWaiting", xml).text() != "0" && $("CallsWaiting", xml).text() != "1"){
//#FF7F7F
$("#N_CallsWaiting").html("<div id='>1_waiting'>");
$("#N_CallsWaiting").append($("CallsWaiting", xml).text());
$("#N_CallsWaiting").append("</div>");
el = document.getElementById('N_CallsWaiting');
el.style.backgroundColor = '#FF7F7F';
}
//-- agent ready
var ready = N_AgentsReady+N_AgentsReserved
if($("AgentsReady", xml).text() == "0"){
//#FF7F7F
$("#N_AgentsReady").html("Ready: " + ready);
el = document.getElementById('N_AgentsReady');
el.style.backgroundColor = '#FF7F7F';
}
if($("AgentsReady", xml).text() == "1"){
//#FFFF68
$("#N_AgentsReady").html("Ready: " + ready);
el = document.getElementById('N_AgentsReady');
el.style.backgroundColor = '#FFFF68';
}
if($("AgentsReady", xml).text() != "0" && $("AgentsReady", xml).text() != "1"){
//#A5FF7F
$("#N_AgentsReady").html("Ready: " + ready);
el = document.getElementById('N_AgentsReady');
el.style.backgroundColor = '#A5FF7F';
}
//-- Calls Today
if(N_CallsToday == 0){
//#A5FF7F
$("#N_CallsToday").html($("CallsToday", xml).text());
el = document.getElementById('N_CallsToday');
el.style.backgroundColor = '#A5FF7F';
}
if(N_CallsToday > 0 && N_CallsToday < 25){
//#FFFF68
$("#N_CallsToday").html($("CallsToday", xml).text());
el = document.getElementById('N_CallsToday');
el.style.backgroundColor = '#FFFF68';
}
if(N_CallsToday >= 25 && N_CallsToday < 50){
//orange
$("#N_CallsToday").html($("CallsToday", xml).text());
el = document.getElementById('N_CallsToday');
el.style.backgroundColor = 'orange';
}
if(N_CallsToday >= 50){
//#FF7F7F
$("#N_CallsToday").html($("CallsToday", xml).text());
el = document.getElementById('N_CallsToday');
el.style.backgroundColor = '#FF7F7F';
}
//-- agents talking
if($("AgentsTalking", xml).text() == "0"){
//#A5FF7F
$("#N_AgentsTalking").html("Talking: " + $("AgentsTalking", xml).text());
el = document.getElementById('N_AgentsTalking');
el.style.backgroundColor = '#A5FF7F';
}
if($("AgentsTalking", xml).text() == "1"){
//#FFFF68
$("#N_AgentsTalking").html("Talking: " + $("AgentsTalking", xml).text());
el = document.getElementById('N_AgentsTalking');
el.style.backgroundColor = '#FFFF68';
}
if($("AgentsTalking", xml).text() != "0" && $("AgentsTalking", xml).text() != "1"){
//#FF7F7F
$("#N_AgentsTalking").html("Talking: " + $("AgentsTalking", xml).text());
el = document.getElementById('N_AgentsTalking');
el.style.backgroundColor = '#FF7F7F';
}
//set div talking and ready containers to nothing
$("#AgentsReady").html("")
$("#AgentsTalking").html("")
$("#AgentsReserved").html("")
//-- output a name list of agents reserved appended to the agents ready div
//NT: these are agents that have a incoming call ringing on their phone
var i = 0;
for (i = 0; i < agent_reserved_names.length-1; i++) {
if(agent_reserved_names[i] != ""){
//append all names to the div tag
$("#AgentsReserved").append("<tr><td>");
$("#AgentsReserved").append(agent_reserved_names[i]+"<br>");
$("#AgentsReserved").append("</td></tr>");
}
}
//el = document.getElementById('AgentsReserved');
//el.style.backgroundColor = '#FFFF68';
if(N_AgentsReserved > 0){
//if there is a call ringing on a reserved agents phone, apply the pulse
/*
$("#AgentsReserved").pulse({
speed: 300,
backgroundColors: ['#A5FF7F','#FFFF68'],
borderColors: ['#FFFF68','#A5FF7F']
});
*/
el = document.getElementById('AgentsReserved');
el.style.backgroundColor = '#FFFF68';
}
//-- output a name list of agents ready
for (i = 0; i < agent_ready_names.length; i++) {
if(agent_ready_names[i] != ""){
//append all names to the div tag
$("#AgentsReady").append("<tr><td>");
$("#AgentsReady").append(agent_ready_names[i]);
$("#AgentsReady").append("</td></tr>");
}
}
el = document.getElementById('AgentsReady');
el.style.backgroundColor = '#A5FF7F';
//-- output a name list of agents talking
for (i = 0; i < agent_talking_names.length; i++) {
//append all names to the div tag
if(agent_talking_names[i] != ""){
//$("#AgentsTalking").append("<tr><td>");
$("#AgentsTalking").append(agent_talking_names[i]+"<br />");
//$("#AgentsTalking").append("<tr><td>");
}
}
el = document.getElementById('AgentsTalking');
el.style.backgroundColor = '#A5FF7F';
historical_agents_talking = agents_talking_currently
}
});
//set the que refresh to 2 seconds
//recursivly call the main function
setTimeout("call_queue()", 2000);
});
}
//loading holder
var loading = true;
//set nightmode value
var is_nightMode = false;
//initial function call
call_queue();
[/code]