View Full Version : Memory problem (when using Dom events)

11 Sep 2008, 11:13 PM
Sorry for my poor English.
Yesterday When I was making an ext application,
Windows show an error message,
"Running out of memory"(in japanese).
I ran the Task Manager,and noticed that
when I click the reload button,the PF usage is
getting higher.

I tryied to fix this.
And found the following doesn't cause this problem.

var mb=Ext.getDom('startb');
It seems that Dom's event cause this problem.

Sorry for my poor English again.
But I would like to know why this happen,and
how to use Dom's Event securely.

Thank you very much.

12 Sep 2008, 12:26 AM
You should specify also the browser you are using, it could help.
I bet it is IE6 :)
Anyway, if you are using "raw" dom and you attach events directly to it, you could come across to memory leak due to cyclic structures between dom and javascript


When a DOM object contains a reference to a JavaScript object (such an event handling function), and when that JavaScript object contains a reference to that DOM object, then a cyclic structure is formed. This is not in itself a problem. At such time as there are no other references to the DOM object and the event handler, then the garbage collector (an automatic memory resource manager) will reclaim them both, allowing their space to be reallocated. The JavaScript garbage collector understands about cycles and is not confused by them. Unfortunately, IE's DOM is not managed by JScript. It has its own memory manager that does not understand about cycles and so gets very confused. As a result, when cycles occur, memory reclamation does not occur. The memory that is not reclaimed is said to have leaked. Over time, this can result in memory starvation. In a memory space full of used cells, the browser starves to death

You could also check http://www.hedgerwow.com/360/dhtml/ie6_memory_leak_fix/ out
Hope this helps

12 Sep 2008, 5:11 AM
Yes,I am using IE6.
I will try thse articles.
(But I am afraid it is a little difficult for me.)
Tank you very much.

12 Sep 2008, 5:29 AM
My suggestion is to check out the Ext components and use them, so that you do not need to worry about these leeks (in theory).
For example, in your code I think you are using a button, so you can check the corrispondent component in Ext and use it instead of a normal button; each component in Ext exposes some "events" and you can attach you handlers to these events easly.
Check out API doc and tutorial for further info and of course, you need start looking at the code of the examples you can find within the dowloaded Ext SDK folder.