//Following function add new table entry to table
//and return interface which has function which uses closure to access and update the table
var _newRow = (function(){
var _interface = {
updateName: null,
updateProgress: null,
actionLinkButton : null,//<a> tag used for user aciton to perform on UI like delete, hide, show etc.
..
..
..
};
var tr = createTr();
var tdName = createTd();
_inteface.updateName = function(newName){
tdName.innerHTML = newName;
}
..
..
..
..
..
return _interface;
})(tblObject);
//maintaining the array of all the rows as per row number
rowArray[rowNo] = _newRow;
..
..
//using the row array to update the entries
rowArray[rowNo].updateProgress('read');
위의 내용은 클라이언트 쪽에서 동적으로 추가 된 행을 업데이트하는 데 사용한 패턴입니다. 내가 할 일은 테이블에 행을 추가하는 동안 _interface를 만들고 반환하고 행 번호별로 저장하는 것입니다.자바 스크립트 클로저 및 메모리 문제
그러나 이것을 위해 나는 클로저를 사용하여 많은 살아있는 개체를 의미합니다. 이 올바른 방법인지 알고 싶습니다. 이게 더 나은 접근법인가? 이 코드가 얼마나 많은 memeory를 사용하고 있는지 알기 위해 사용할 수있는 프로파일 링 도구는 무엇입니까? 클로저가 필요하지 않을 때 제대로 지워지도록하려면 어떻게해야합니까?
FireFox 용 플러그인 인 http://getfirebug.com/을 보거나 Webkit 브라우저 (Google Chrome, Safari)에서 프로파일 러를 빌드하십시오. – Kevin
예, 사용 중입니다. 그러나 그것은 메모리와 힙 크기를 나타내지 않습니다. 또한 잘못된 관행이나 메모리 크기가 증가하지 않습니다. 다른 도구가 있습니까? –