Created
October 30, 2013 03:10
-
-
Save lizzie/7226633 to your computer and use it in GitHub Desktop.
IE8- 下, jQuery 绑定自定义事件之后, 无法删除导致内存泄露问题
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jQuery 1.7.2- removeEvent 的代码 | |
function( elem, type, handle ) { | |
if ( elem.detachEvent ) { | |
elem.detachEvent( "on" + type, handle ); | |
} | |
}; | |
// jQuery 1.8.0+ removeEvent 的代码 | |
function( elem, type, handle ) { | |
var name = "on" + type; | |
if ( elem.detachEvent ) { | |
// #8545, #7054, preventing memory leaks for custom events in IE6-8 – | |
// detachEvent needed property on element, by name of that event, to properly expose it to GC | |
if ( typeof elem[ name ] === "undefined" ) { | |
elem[ name ] = null; | |
} | |
elem.detachEvent( name, handle ); | |
} | |
}; | |
// 相关 https://github.com/markelog/jquery/commit/71260802ab48e3926e56b5d2ff819e1a53d8217c | |
// - http://www.reigndropsfall.net/2011/01/05/internet-explorer-event-handler-leaks/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment