SamuelBiddulph
IS-IT--Management
Not sure if this is the exact place to post this but here goes;
I've a webpage that has a memory leak and for the life of me i can't restructure the code to resolve this - unfortunatly i'm in no way an expert so i've tried by best but get the same leaking result.
Please can any helpful people take a look at the code and perhaps give me an indication as to what needs to get changed.
Basically this page auto refreshs itself every 10 seconds and if there is a problem connecting to the server it loads an 'error' page. All works fine apart from the leak that happens.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript">
//XMLHttpRequest object
var request;
var targetServerURL;
var normalFrame;
var errorFrame;
function createRequest() {
try {
//since our target environment is IE 6.0. so ingore other browsers.
request = new ActiveXObject("Msxml2.XMLHTTP.6.0");
setTimeout( "gettargetInfo()", 10*1 );
} catch (othermicrosoft) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
request = false;
}
}
if (!request)
alert("Error initializing XMLHttpRequest!");
}
function gettargetInfo() {
//if the request is null, create the XMLHTTPRequest object,
//it only occurs at the gettargetInfo() method first time running.
// if(request==null)
// {
// createRequest();
// }
try{
//put the target Server URL here,it depends on the how the target Server
//IP address and how target Web application be deployed(Web Context).
//for example,target Server URL: //the dummy parameter is added to avoid the local cache.
var targetServerURL = " + new Date().getTime();
request.open("GET", targetServerURL, true);
request.onreadystatechange = updatePage;
request.send(null);
}
catch(e)
{
delete errorFrame;
//If some error cccurred, display an error page and try ervery 10 seconds.
var errorFrame = window.open("Error.html","New", "fullscreen=yes");
errorFrame.focus();
setTimeout( "gettargetInfo()", 10*1000 );
}
function updatePage() {
//wait until the connection is completed.
if (request.readyState == 4)
{
//if get the status code is 200 then display the the target page and refresh the page every 10 seconds. otherwise display an error page and try every 10 seconds.
if((request.status == 200)&&(request.status!=500))
{
delete targetServerURL;
delete normalFrame;
var targetServerURL = " + new Date().getTime();
var normalFrame = window.open(targetServerURL,"New", "fullscreen=yes");
normalFrame.focus();
setTimeout( "gettargetInfo()", 10*1000 );
}
else
{
delete errorFrame;
var errorFrame = window.open("Error.html","New", "fullscreen=yes");
errorFrame.focus();
setTimeout( "gettargetInfo()", 10*1000 );
}
}
}
}
</script>
<body bgColor="black" onload="window.setTimeout('createRequest()',10*1000);" style="overflow: hidden">
<P><FONT size="4" face="Tahoma" color ="Yellow">Loading Web page from the Display System Server...</FONT>
</P>
</body>
</html>
I've a webpage that has a memory leak and for the life of me i can't restructure the code to resolve this - unfortunatly i'm in no way an expert so i've tried by best but get the same leaking result.
Please can any helpful people take a look at the code and perhaps give me an indication as to what needs to get changed.
Basically this page auto refreshs itself every 10 seconds and if there is a problem connecting to the server it loads an 'error' page. All works fine apart from the leak that happens.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript">
//XMLHttpRequest object
var request;
var targetServerURL;
var normalFrame;
var errorFrame;
function createRequest() {
try {
//since our target environment is IE 6.0. so ingore other browsers.
request = new ActiveXObject("Msxml2.XMLHTTP.6.0");
setTimeout( "gettargetInfo()", 10*1 );
} catch (othermicrosoft) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
request = false;
}
}
if (!request)
alert("Error initializing XMLHttpRequest!");
}
function gettargetInfo() {
//if the request is null, create the XMLHTTPRequest object,
//it only occurs at the gettargetInfo() method first time running.
// if(request==null)
// {
// createRequest();
// }
try{
//put the target Server URL here,it depends on the how the target Server
//IP address and how target Web application be deployed(Web Context).
//for example,target Server URL: //the dummy parameter is added to avoid the local cache.
var targetServerURL = " + new Date().getTime();
request.open("GET", targetServerURL, true);
request.onreadystatechange = updatePage;
request.send(null);
}
catch(e)
{
delete errorFrame;
//If some error cccurred, display an error page and try ervery 10 seconds.
var errorFrame = window.open("Error.html","New", "fullscreen=yes");
errorFrame.focus();
setTimeout( "gettargetInfo()", 10*1000 );
}
function updatePage() {
//wait until the connection is completed.
if (request.readyState == 4)
{
//if get the status code is 200 then display the the target page and refresh the page every 10 seconds. otherwise display an error page and try every 10 seconds.
if((request.status == 200)&&(request.status!=500))
{
delete targetServerURL;
delete normalFrame;
var targetServerURL = " + new Date().getTime();
var normalFrame = window.open(targetServerURL,"New", "fullscreen=yes");
normalFrame.focus();
setTimeout( "gettargetInfo()", 10*1000 );
}
else
{
delete errorFrame;
var errorFrame = window.open("Error.html","New", "fullscreen=yes");
errorFrame.focus();
setTimeout( "gettargetInfo()", 10*1000 );
}
}
}
}
</script>
<body bgColor="black" onload="window.setTimeout('createRequest()',10*1000);" style="overflow: hidden">
<P><FONT size="4" face="Tahoma" color ="Yellow">Loading Web page from the Display System Server...</FONT>
</P>
</body>
</html>