11
I have a JavaScript closure which I keep recreating throughout the life time of my web application (single full-ajax page).
I would like to know if it's creating a memory leak.
Here is an example JSFIDDLE
The code in question:
function CreateLinks() {
var ul = $("<ul></ul>").appendTo('div#links');
for (var i in myLinks) {
var li = $('<li>' + myLinks[i].name + '</li>').appendTo(ul);
//closure starts here
(function (value) {
li.click(function (e) {
$('div#info').append('<label>' + value + '</label><br />');
RecreateLinks();
});
})(myLinks[i].value);
}
}