Re: Memory leak on adding Form to a DOM node



Simon_21 wrote:
it is in addRowToTable()
cellLeft.innerHTML ="<FORM id="+ "form_"+rownum++ +
"<A>default.domain.invalid.default.domain.invalid</A></FORM>";

The moment I change the form to something else the leak stops, but I
don't have a clue why it leaks.

First, there is useless concatenation.

cellLeft.innerHTML = '<FORM id="form_' + (rownum++) +
'<A>default.domain.invalid.default.domain.invalid</A></FORM>';

Second, there is too much concatenation.

cellLeft.innerHTML = new Array(
"<FORM id='form_", rownum++,
"<A>default.domain.invalid.default.domain.invalid</A></FORM>"
).join("");

Third, this generates invalid markup, the <form> tag is incomplete.
Also, attribute values are not quoted (not a syntax error, but a
possible cause for the leak as the UA has to parse the markup).

cellLeft.innerHTML = new Array(
'<FORM id="form_', rownum++, '">',
"<A>default.domain.invalid.default.domain.invalid</A></FORM>"
).join("");

Fourth, the generating markup is not Valid itself: ETAGOs must be escaped
in HTML `script' element content or the element ends prematurely.

cellLeft.innerHTML = new Array(
'<form id="form_', rownum++, '">',
'<a>default.domain.invalid.default.domain.invalid<\/a><\/form>'
).join("");

Fifth, the generated markup is useless: the generated `a' element has
neither a `name', nor an `id' or a `href' attribute. What is the UA
supposed to do with that?

And don't forget to include

cellLeft = null;

after that.

But you have not posted the real code, so the above can only give you a hint
as to possible improvements of your code that might or might not solve the
problem. Also, from the sheer length of the wrapped code posted in
<1190092952.341003.177810@xxxxxxxxxxxxxxxxxxxxxxxxxxx>, it would not be
unreasonable to assume that MSHTML has its problems with that long a line.

That said, the proprietary `innerHTML' property should not be used anyway.
If you build the subtree with DOM Level 2 methods, you would stand much
less a chance to run into such apparent flaws of the DOM implementation.


HTH

PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
.



Relevant Pages

  • Re: Fix for memory leak in setenv/unsetenv
    ... so you are preserving the leak. ... y finds w within the array and reuses it. ... getenv() is performing a linear search for the first active occurrence ... values of environment variables would result in nearly reasonable ...
    (freebsd-current)
  • Re: Tracking Memory leak
    ... Some compilers leak memory when a function returns either an ... array or a pointer to an array. ... memory, then experimenting with "some_size" might help ... it would help if you mentioned the compiler brand name, ...
    (comp.lang.fortran)
  • Re: Arrays
    ... If you copy over pointer types, then you get a memory leak. ... I haven't looked closely at your implementation, but when shifting blocks around inside a multi dimension array, these potentials for leaks are very real. ... ReDim Preserve columns ...
    (microsoft.public.vb.general.discussion)
  • Re: Cannot use DEBUG_NEW to trace this leak.
    ... In addition to what Dave & G said, you don't list what 'n' is equal to so perhaps you are memsetting past the end of the array of std:strings. ... I am also not sure why you would want to create an array of them that wya, but if you do the memset size should match the new size if you're trying to set an array to all nulls. ... Dumping objects -> ... I have no leak. ...
    (microsoft.public.vc.mfc)