[webkit-dev] innerHTML and removeChild ... not freeing memory

Purushottam Sholapur purushottam.sholapur at gmail.com
Wed Mar 25 08:48:58 PDT 2009


Hi all,

I am using QT/Webkit-4.5 (embeded version) on linux. I am trying to use
createElement, innerHTML, appendChild and later removeChild.

UI Output is perfectly fine. But when I do removeChild, div momory is not
freed. Is there anything wrong with the code. Since the div contains image,
lot of memory is hogged and not freed.

------------Below is the code...
Click on "Add Some Elements" to add the div to innerHTML
Click on "Remove the div" to remove the div
------------
<html>
    <head>
        <title>Test script</title>
        <script language="javascript">
        function removeElement(divNum) {
            var divIdN = 'my'+divNum+'Div';
            var olddiv = document.getElementById(divIdN);
            olddiv.parentNode.removeChild(olddiv);
            olddiv = null;
        }
        function addElement() {
            var ni = document.getElementById('myDiv');
            var numi = document.getElementById('theValue');
            var num = (document.getElementById('theValue').value -1)+ 2;
            numi.value = num;
            var newdiv = document.createElement('div');
            var divIdName = 'my'+num+'Div';
            newdiv.setAttribute('id',divIdName);
            ni.appendChild(newdiv);
            newdiv.innerHTML = 'Element Number '+num+' has been added! <a
href=\'#\' onclick=\'removeElement('+num+')\'>Remove the div
"'+divIdName+'"</a>'+'<img src="
http://www.play-montreal.com/wordpress/wp-content/uploads/2007/10/biosphere-1.jpg<http://localhost/share/biosphere-1.jpg>"
/>';
            ni = null;
            newdiv = null;
        }
        </script>
</head>
<body>
<input type="hidden" value="0" id="theValue" />
<p><a href="javascript:;" onclick="addElement();">Add Some Elements</a></p>
<div id="myDiv"> </div>
</body>
</html>
-----------------
regards
Purush
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20090325/230c994c/attachment.html>


More information about the webkit-dev mailing list