On Apr 7, 3:17 am, "Karl Rudd" <[EMAIL PROTECTED]> wrote:
> You'll need a record of every function and variable that a script
> defines. Perhaps a function that does the "clean up". For instance
> (untested):
>
> var blah = 3;
> var blahblah = { 'f': 12 };
>
> function aFunc() { };
> function aFunc2() { }
>
> function cleanUp() {
>   blah = undefined;
>   blahblah = undefined;
>   aFunc = undefined;
>   aFunc2 = undefined;
>
> }

If you can structure your scripts like this, then it could work.
However, you might be better served to do:

  function cleanUp() {
    delete blah;
    delete blahblah;
    delete aFunc;
    delete aFunc2;
    setTimeout(function(){delete cleanUp},0);
  }

And you still might be stuck with hanging references in any
event handlers that are defined. Your cleanUp function would
need to remove those as well, e.g.:

  btn = document.getElementById('someButton');
  btnHandler = btn.onclick;
  function myhandler() {
    // do some stuff
    btnHandler();
  }
  btn.onclick = handler;

  function cleanUp() {
    // cleanup variables and functions as above.

    // restore old event handler
    btn.onclick = btnHandler;
    delete myhandler;
    delete btnHandler;
  }

Obviously, this can get *really* hairy.

--

hj

Reply via email to