KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
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); } }
Tags (comma-separated)
Save Edits
Cancel