user773237
user773237

Reputation: 13

.net MVC and JQuery ajax refresh memory leak

I've looked through forums trying to find a resolution to my issue but can't find anything similar. I see lots of memory leak issues though but still can't find one particular to mine. I'm pretty new to jquery too.

So I have a .net mvc page that queries a database a refreshes a div every 3 seconds. I notice it constantly is eating up memory and then eventually crashing once it hits around 1gb of memory. I'm using IE8. Here is the page:

<script type="text/javascript">
var refreshInterval = 3000;
var refreshInSeconds = refreshInterval / 1000;

$(document).ready(
                 function () {
                     $("#timerValue").text(refreshInSeconds.toString());
                 });

$(function () {
    setInterval(
            function () {
                $.ajax({
                    url: '<%:Url.Action("RefreshRunningSuites")%>',
                    context: document.body,
                    cache: false,
                    success: function (data) {
                        $("div#runningSuites").html(data);
                    }
                });
            },
            refreshInterval);
});

</script>
<h2>
    Currently Running Suites</h2>
<br />

<div id="runningSuites">

 <% Html.RenderPartial("RunningSuites", Model); %>
</div>
<div id="footer">

    Listing refreshes every <label id="timerValue"></label> seconds.
</div>

The RunningSuites user control loops through the list contained in the viewmodel object passed in and renders a new tablerow for each record in the list inside of a normal html table

Here is the ActionResult RunningSuites

public ActionResult RefreshRunningSuites()
{
    RunningSuitesViewModel viewModel = new RunningSuitesViewModel(RunManager.GetCurrentlyRunningSuites());
    return PartialView("RunningSuites", viewModel);
}

Any idea how to resolve this memory leak? Thanks.

Upvotes: 1

Views: 2106

Answers (1)

Adam Tuliper
Adam Tuliper

Reputation: 30152

The same situation as yours is reported here: http://forum.jquery.com/topic/memory-leaks-with-ajax-calls

The workaround (if you are using that version <1.5 and it's not cleared in 1.5+ - but you'll need to check those versions I'm not sure if its fixed)

Clear out your content first (document.getElementById("runningSuites")).innerHTML = "";

This 'may' have been fixed in jQuery 1.5 - give it a whirl if not use the workaround.

Fyi to help with DOM leaks check out this to possibly get more info

http://www.smallworkarounds.net/2009/04/jquery-leaking-memory-be-careful-while.html\

Upvotes: 2

Related Questions