JavaScript에서는 함수, 변수 및 클로저로 구성된 복잡한 객체가 있습니다.JavaScript에서 객체를 삭제하는 가장 좋은 방법은 무엇입니까?
이 개체는 매우 크고 복잡하며 반복적으로 만들어지고 파괴됩니다. 나는 매우 저전력, 매우 낮은 메모리 장치에서 작업 할 것이므로, 객체가 삭제되면 실제로 없어 졌음이 중요합니다.
fun2(); // 2
// Interval: "f.o.u.r.", "f.o.u.r.", "f.o.u.r.", "f.o.u.r." ...
그 대해 할 수 있나요 (:
window["obj"] = {};
obj.fun1 = function(){
console.log(1);
};
(function(){
var n = 2;
function fun(){
console.log(n);
}
obj.fun2 = fun;
})();
(function(){
var w = "Three";
function fun(){
console.log(w);
}
obj.fun3 = fun;
})();
(function(){
var w = "f.o.u.r.";
function fun(){
setInterval(function(){
console.log(w);
}, 1e3); // e.g. a timeout
}
obj.fun4 = fun;
})();
obj.fun1();
obj.fun2();
obj.fun3();
obj.fun4();
var fun2 = obj.fun2;
// window.obj = null;
// window.obj = undefined;
delete window.obj;
console.log(typeof obj); // undefined
보조 문제는 다음과 같은 "느린 참조"의 질문은 다음과 같습니다
는 코드 예제 개체를 삭제하기 전에 수동 정리 제외)? http://jsfiddle.net/8nE2f/
참조 http://stackoverflow.com/questions/8467350/how-to-free-up-the-memory-in-javascript-to obj = null; – davidkonrad
개체를 삭제하려는 경우 참고? –
그리고 이것 : http://stackoverflow.com/questions/8310182/better-approach-nulling-variables-objects-in-javascript – Rudy