Javascript memory leak when adding to the DOM? *EXPERT*

Discussion in 'JavaScript' started by GreatMetro, Mar 13, 2008.

  1. #1
    Hi there,
    maybe not the best title. I'm using ajax to pull information from a database via a PHP script that returns JSON. I then use javascript on the originating page to decipher the JSON, create some HTML, containing DIVS, and output it into a innerHTML of a DIV. As each ajax call is made, the innerHTML is emptied, and then repopulated with the new data. On average, the data is about 20-60K.

    I find that when I do that more than 10 times, firefox gets real slow, and I'm wondering if reloading data into a DIV over and over via innerHTML causes memory to get eaten up?

    Also, would it be better to actually insert elements into the DOM via prototype, and then delete them at each call, or is simply updating the innerHTML ok?

    Thanks in advance


    PS MARL is a scam.
     
    GreatMetro, Mar 13, 2008 IP
  2. LogicFlux

    LogicFlux Peon

    Messages:
    2,925
    Likes Received:
    102
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I would try creating and deleting the container element on each request to see if the problem goes away. Have you tried it yet?
     
    LogicFlux, Mar 14, 2008 IP