memory leak in dlgMessage(), dlgAlert(), dlgConfirm()

Issue #120 resolved
dd1 created an issue

controls.js functions dlgMessage(), dlgAlert(), dlgConfirm() have a memory leak - they unconditionally create <div> elements attached to the html document that are never deleted. Do we need to create a new <div> for each alert and message? Can we create <div> with fixed id and keep reusing it, like dlgBlackout already does? K.O.

Comments (1)

  1. Stefan Ritt

    Nope. When you close the dialog, dlgMessageDestroy() calls

    document.body.removeChild(dlg)
    

    which removes the <div> from the page. The <div> still exists in memory, but because there is no reference to it any more, it's deleted automatically whey you exit the scope of dlgMessageDestroy(). JavaScript is not C++ and has a different memory model including a garbage collector.

    Please read https://developer.mozilla.org/en-US/docs/Web/JavaScript/Memory_Management for your education.

  2. Log in to comment