Javascript time to force full postback

I have a heavy AJAX site that has to run on IE6&7 - this is causing memory leaks.

The solutions after many weeks of debugging seems to be to have a full postback every now and then.

I currently have a javascipt timer that rund for 60 mins then does a document.forms[0].submit()

The problem with this is the page has pop up, and I dont want the page to postback while the user has a pop up open, as this clears.

I'm at the limit now of my JS skills. I need a javascript time function that I can stop when the pop up opens and continues when the pop up closes.

Doe anyone have such a script?

Andy GreenAsked:
Who is Participating?
Andy GreenAuthor Commented:
Thanks for the replies, but I have found my own solution.

I have the following Script:
var secs
var timerID = null
var timerRunning = false
var delay = 1000

function InitializeClearDataTimer() {
    secs = 360 //set the timer delay

function StopTheClock() {
    if (timerRunning)
    timerRunning = false

function StartTheTimer() {
    if (secs == 0) {
    else {
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)

Open in new window

In the function that opens the pop up I have - StopTheClock()
And in the function that fires the AJAX to re populate the grid I have -  StartTheTimer();

This seems to work OK

You could take the start time when you set your timeout for doing the postback, then just before opening the popup calculate the amount of time remaining and cancel the timeout. After the popup is closed you can then create a new timeout using the remaining time.

I've not tested the following, but this is the approach I would take...

// Initialisation
// Start the count down to posting back and record the current time in milliseconds
postbackId = setTimeout("postback()", 60000);
startTime = (new Date()).getTime();

// Before opening popup...
// Get time remaining time.
remainingTime = 60000 - ((new Date()).getTime() - startTime);
// Now open popup...

// After closing the popup..
// recalculate the start time to be now - the time elapsed before the popup was opened, and timeout on the remaining time.
startTime = (new Date()).getTime() - (60000 - remainingTime);
postbackId = setTimeout("postback()", remainingTime);

Open in new window

Heavy AJAX on IE6/7 requires extremely careful programming. The reload you are suggesting will probably only delay the memory issue, not prevent it.

I have been there before, with an enterprise app that leaked memory up to where it wasn't usable anymore (after about 5-6 hours of usage). A reload helped, but not all memory would free up. After about 10 hours of usage, a reload didn't help at all - the IE process had to be killed.

My advice is to look at the memory leaks and fix them. A common issue in IE6/7 is manipulation of DOM content that isn't there. Another big no no is to append/remove DOM elements instead of show/hide.
Andy GreenAuthor Commented:
I have found my own solution.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.