unload/remove a js script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vituko
    New Member
    • Dec 2006
    • 48

    unload/remove a js script

    im working with ajax and i load scripts dinamically :

    createElement ('script') and script.src / script.text

    but the reverse way doesnt work, after : script.parentNo de.removeChild (script), the functions and variables are still there, memory was not cleaned.

    Does anybody know how it can be done or have other aproaches?

    Thanks
  • b1randon
    Recognized Expert New Member
    • Dec 2006
    • 171

    #2
    Originally posted by vituko
    im working with ajax and i load scripts dinamically :

    createElement ('script') and script.src / script.text

    but the reverse way doesnt work, after : script.parentNo de.removeChild (script), the functions and variables are still there, memory was not cleaned.

    Does anybody know how it can be done or have other aproaches?

    Thanks
    That's pretty interesting. What do you achieve by removing the scripts? Are you sure you really need to remove them?

    Comment

    • AricC
      Recognized Expert Top Contributor
      • Oct 2006
      • 1885

      #3
      What are you creating with these dynamic scripts? I agree with the above statement perhaps you don't need to get rid of them.

      Comment

      • mrhoo
        Contributor
        • Jun 2006
        • 428

        #4
        The only way to delete a loaded script from memory is to reload the page without it.

        You can explicitly set the objects and methods declared in the script to null,
        but that can have serious side effects on any thing remaining on the page that was instantiated or modified by the script.

        If you can cover that, and make everything in the script a method or property of some single global object that is NOT declared with the var keyword, you can delete the global- but keep your fingers crossed, and test the stuffing out of it.

        script-
        Glob={
        // define everything as a property of global object;
        }
        Call methods of Glob while you need it.

        and then delete Glob

        Comment

        • vituko
          New Member
          • Dec 2006
          • 48

          #5
          Yes, I suposed, but I wanted to believe. I found logic that the browser keeps links between data and the node from where they where invoqued. But I'll try nothing more, the only way from today for me is to program object oriented, encapsulate all data, it's really a better way also for many other reasons, but I'm a little lazy, I must recycle a lot of code (ok, not so much).

          I need to load and unload libraries (from today classes), because Im working in an ajax site, 100% ajax and there are js animations (I dont like macromedia), a lot of code and a lot of memory to manage...

          Thank you very much, I needed another confirmation.

          Muchas gracias, tío. Un saludo desde España.

          Comment

          Working...