javascript

javascript 메모리릭 관련 settimeout memory leak

새로운 도전을 위한 한걸음 2017. 7. 27. 10:28

javascript 메모리릭 관련 

settimeout memory leak


메모리 릭 발생코드 . 

var timeoutObj; 

function testF(){


$.ajax({

type:"POST",

url: 'url',

success:function(result){

timeoutObj= setTimeout(function (){

testF()

}, 1000);

}

});

}

testF()


해결 방법. 

var timeoutObj; 

function testF(){


$.ajax({

type:"POST",

url: 'url',

success:function(result){

clearTimeout(timeoutObj);

timeoutObj= setTimeout(function (){

testF()

}, 1000);

}

});

}

testF()



참고 사이트 

https://developer.mozilla.org/ko/docs/Web/JavaScript/Memory_Management


구글 개발자도구 메모리 할당 프로파일러 도구 사용법 

https://developers.google.com/web/tools/chrome-devtools/memory-problems/allocation-profiler?hl=ko


https://developers.google.com/web/tools/chrome-devtools/memory-problems/?hl=ko#allocation-profile