Gino Cochuyt spent some hours to find the cause of memory leaks in IE when using instanceof.
He found at least 3 Objects that cause the memory leaks:
- window
- document
- element
Just using - if (window instanceof Object) - for example causes a memory leak! that grows by 50 KB per refresh; the reason for this is because these 3 Objects are not really objects in IE (they don’t have a constructor); the same reason why they don’t have the Native Object methods:
- hasOwnProperty
- valueOf
where in other Browsers like FF, Opera and Safari … (the ones that i tested!)
a div elemement for example is an instanceof HTMLDivElement - HTMLElement - Node etc..
To prevent these memory leaks:
-
-
function MyClass(){};
-
-
function testIt (obj) {
-
if (!obj || !obj.hasOwnProperty || !(obj instanceof MyClass)) {…}
-
// IE will fail on the second statement if obj == window || document…. so the instanceof statement doesn’t get tested!!
-
};
-
No User Responded in " Working aroung the instanceof memory leak "
Sorry the comment area are closed