Which of following JavaScript snippets will leak memory?
snippet #1:
function foo(obj)
{
var obj2 = {};
$('#something').click(function() { alert(obj.id); } );
}
snippet #2:
function foo(obj)
{
var obj2 = {}
$('#something').click(function() { alert('obj was not used.'); } );
}
snippet #3:
function foo(obj)
{
var obj2= {id: 1}
bar(function() { alert(obj2.id); } );
}
function bar(func)
{
var obj3 = {};
func();
}
and which variables won't be collected by Garbage Collector? How to fix leaks?