Mitul Dabhi
answered Nov 30 '-1 00:00
Mostly programming / script Language have its own memory management module , where it work as garbage collector which free memory block which is not in use , if this not happen properly than memory stack increase and sometime result is application crash .
when we initialize a variable which is not in use and if it not freed by program it will remain until program run end.so as increase of unused variable / program data , memory use also increase.which is cause memory leak
JavaScript code ::
function dd(){
logr='me local';
}
dd();
console.log(logr);// me local
in above example we defined the variable in function it look local and should be garbage collected in the end of function run but when we do acess of it at after run of the function . it is still in memory and it will remain until the program end.its called memory leak .
let me explain how it can be avoid
function dd(){
var logr='me local';
}
in above function we use var to make it local if you do not define with var than JavaScript make it global which is not expected and it cause memory leak.so do care of when you define variable .