I am reading lot of articles regarding memory leaks. But i am not sure about below code. I usually do coding in this way. Can anyone tell me, will they leak memory?
I have doubts in following 3 scenarios (marked them in code).
I got these suspects after reading this post
var orderDetails = $("<root/>"); function GetOrderDetais() { $.ajax( { url: url, dataType: 'xml', data: someThing, dataType: 'text', type: 'POST', contentType: "text/xml; charset=utf-8", success:function(value) //1 - closure function refrencing global variable { orderDetails = $(value); orderDetails.find("header").each(function() //2 - closure function refrencing global variable { //loop through order header details and do some DOM appends here. }); ShowOrderDetails(); }, error:function(jqXHR, textStatus, errorThrown) { alert("Error" + textStatus + " ==> " + errorThrown); }, }); } function ShowOrderDetails() { var orderNum = orderDetails.find("header oNum").text(); $(orderDetails).find("item").each(function() //3 - closure function refrencing outer variable { //loop through item details and do some DOM appends here to form table. //one intresting statement. $("div").append($(this).find("itemNum").text() + " - " + orderNum); }); } Update:
See this Video to learn about memory leake.