开发者

Memory leak using jquery-ui/datepicker

I'm using these scripts (where jquery-ui[].custom.js is the datepicker plugin):

<script src="../../Scripts/jquery-1.5.1.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-1.8.13.custom.js" type="text/javascript"></script>
<script id="formvalidation" type="text/javascript">
$(document).ready(function () {
    $(".datepicker").datepicker(开发者_如何学Python{ dateFormat: 'dd/mm/yy' });
});
</script>

On this input element (inside a form):

<input type="text" name="Date" class="datepicker" />

The page loads fine and when I click in the input field the datepicker pops up correctly, but I get a memory leak (in every browser) once a date is selected and the datepicker disappears. This causes that bit of JS to crash or slow down the browser because of a memory leak in jquery-1.5.1.js:

Line: 1520 Error: Out of memory

When debugging I see the error line is at 2310

jQuery.event.remove( elem, type + types );

A little context:

// Unbind all events for the element
if ( !types || typeof types === "string" && types.charAt(0) === "." ) {
    types = types || "";
    for ( type in events ) {
        jQuery.event.remove( elem, type + types );
    }
    return;
}

Am I doing something wrong or maybe its a bug in jquery? I'm also using the validation plugin but the same error occurs when I disable it.

[Solved?] Since I can't post my answer for 8 hours:

Solved the leak by switching to the minimal version of jquery (jquery-1.5.1.min.js & jquery-ui-1.8.13.custom.min.js). It appears there is some discrepancy between the min version and the dev version.

Side question: Where would be a good place to bring this up if its not already an issue?


Solved the leak by switching to the minimal version of jquery (jquery-1.5.1.min.js & jquery-ui-1.8.13.custom.min.js). It appears there is some discrepancy between the min version and the dev version.

Side question: Where would be a good place to bring this up if its not already an issue?


Probably you want

$(document).ready(function () {
    $(".datepicker").datepicker({ dateFormat: 'dd/mm/yy' });
});

The construct you have above will pass your function to jQuery as a selector with likely unintended consequences.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜