problem with memory leak
Filed under: xn--cnq77f.com
Ive got the problem with memory leak. I use IE engine and when I refresh the page (clicking F5 in IE) the browser has increased the memory by about 500kB to 1MB. Its terrible.
When I remove Your extension to YUI I mean the line:
memory is stable and does not leak.
Have You any idea of how to resolve this problem ?
Peter
I don't see any specific code that looks bad.
drip reports the same problem on a local copy with normal .js serving.
showCat: function() {
var catCols = [{
header: "Category",
width: 255,
editor: new YAHOO.ext.grid.TextEditor()
}];
var catCm = new YAHOO.ext.grid.DefaultColumnModel(catCols);
catCm.defaultSortable = true;
var catDm = new YAHOO.ext.grid.JSONDataModel({
root: 'Categories',
totalProperty: "totalCount",
id: 'id',
fields: ['category']
});
catDm.initPaging('/ci/admin/profile_fields_categories', 10);
catDm.setDefaultSort(catCm, 0, 'ASC');
catGrid = new YAHOO.ext.grid.EditorGrid('admin_user_fields_categ ories', catDm, catCm);
catGrid.getSelectionModel().clicksToActivateCell = 2;
catGrid.render();
var toolbar = catGrid.getView().getPageToolbar();
toolbar.addButton({
className: 'add',
text: "",
click: YAHOO.whasit.newUserFields.addCat
});
YAHOO.whasit.newUserFields.adminFieldsLayout.begin Update();
YAHOO.whasit.newUserFields.adminFieldsLayout.add(' center', new YAHOO.ext.GridPanel(catGrid, {title: 'Categories', fitToFrame: true}));
YAHOO.whasit.newUserFields.adminFieldsLayout.endUp date();
catDm.loadPage(1);
},
addCat: function() {
if ( typeof(newCatDialog) == "undefined" ) {
if ( !document.getElementById('newCatDialog')) {
var dlgDiv = document.createElement("div");
dlgDiv.id = "newCatDialog";
document.body.appendChild(dlgDiv);
}
newCatDialog = new YAHOO.ext.LayoutDialog("newCatDialog", {
modal:true,
autoScroll:true,
width:300,
height:100,
shadow:true,
minWidth:300,
minHeight:100,
center: {
autoScroll:true,
alwaysShowTabs: false,
autoCreate: true
}
});
var layout = newCatDialog.getLayout();
newCatDialog.beginUpdate();
if ( !newCatPane ) {
var newCatPane = layout.add('center', new YAHOO.ext.ContentPanel('newCatPane', {
fitToFrame: true,
autoCreate: true }));
}
newCatDialog.endUpdate();
newCatDialog.header.update('New Category');
newCatDialog.addKeyListener(27, newCatDialog.hide, newCatDialog);
newCatDialog.addButton('Close', newCatDialog.hide, newCatDialog);
submitButton = newCatDialog.addButton('Submit', YAHOO.whasit.newUserFields.submitCat, YAHOO.whasit.newUserFields.showCat);
newCatDialog.syncBodyHeight();
}
getEl('newCatPane').getUpdateManager().update({url : '/ci/admin/newcat', loadScripts: true});
newCatDialog.show();
},
submitCat: function(){
getEl('newCatPane').getUpdateManager().loadScripts = true;
getEl('newCatPane').getUpdateManager().update({url : '/ci/admin/newcat', params: {catName: document.getElementById('newCatName').value}});
},
I'm also trying to figure out why IE errors on "Object doesn't support this property or method" when that toolbar item is clicked. So far it seems to be something with the line - if ( typeof(newCatDialog) == "undefined" ) { - but I haven't figured it out yet.
i came across this site searching for a grid widget and i found a lot more.
now, i tested:
http://www.jackslocum.com/blog/examples/layout1.htm
with drip to check MSIE memory.
drip does not find any leak, however memory usage increment on every reload by 1M.
it goes like this (Mb): 16,17,18,19...100,101,102.... etc, etc. and memory get freed only restarting drip.
if it is not a leak, why IE keep eating memory on every refresh ?
http://javascript.crockford.com/memory/leak.html
This site has a lot of good articles about javascript - Crockford is the guy who created the JSON notation.
my site will be updated with the latest version later when I'm ready to push code updates again
i know it's MSIE fault 'cause firefox does not have this problem, however:
yui http://img295.imageshack.us/img295/1573/dripnormalyf9.gif yui-ext http://img237.imageshack.us/img237/870/dripyuiextac5.gif
the graph shows that in yui-ext memory usage grows linearly with IE.
it must be something in the library that prevent crappy MS browser to release memory.
function foo(node){
node.onclick = function(){
alert(node.id + ' was clicked.';
}
}
That creates a circular reference that is bad. The onclick function has a closure containing the node, and the node has a property (onclick) that contains the function. This is where the big closure scare came from.
http://interpc.pl/~pwywiol/test/splitter.htm
It's almost an empty page (with dblClick on splitter :) implemented by code You sent me).
Try refresh the page to see the memory used by the browser increase. I test it only on IE engine.
I add the purge function to the javascript code. Now the memory leak slowly.
Peter
If you go to http://whasit.com/ci/ and click on Login and Register in the header, and Logger in the footer, you'll see the craziness.
test
YAHOO.util.Event.on(window, 'load', yourLoadFcn);
YAHOO.util.Event.on(window, 'unload', yourUnloadFcn);
Inline load and unload handlers aren't cleaned up and could prevent normal cleanup.
on a side note:
95% Leaks in IE are created by putting JS Objects on DOM nodes
Does that include using onClick for dom nodes? If so looks like I am going to need to refactor a lot of my work.
#If you have any other info about this subject , Please add it free.# |