javascript闭包产生的内存泄漏
2011-09-03 12:09
435 查看
使用时,最好不要使用闭包,可以将函数声明后,直接调用函数名即可。
<html><head><script type="text/javascript">document.write("Avoid leaks by avoiding closures!");window.onload=function(){var obj = document.getElementById("element");obj.onclick = doesNotLeak;}function doesNotLeak(){//Your Logic herealert("Hi!
I have avoided the leak");}</script></head><body><button id="element">"Click Here"</button></body></html>
<html><head><script type="text/javascript">document.write("Avoid leaks by avoiding closures!");window.onload=function(){var obj = document.getElementById("element");obj.onclick = doesNotLeak;}function doesNotLeak(){//Your Logic herealert("Hi!
I have avoided the leak");}</script></head><body><button id="element">"Click Here"</button></body></html>
相关文章推荐
- 内存泄漏(OOM)产生原因
- 内存溢出和内存泄漏的区别、产生原因以及解决方案
- ARC 下代理产生内存泄漏的情况
- C++内存泄漏和内存碎片的产生及避免策略
- block产生的内存泄漏以及解决方案(以及扩展)
- Android内存泄漏就这样产生了
- JavaScript闭包产生的问题
- 内存溢出和内存泄漏的区别、产生原因以及解决方案
- Android内存泄漏就这样产生了
- Android内存泄漏就这样产生了
- C++类对象之间赋值产生内存泄漏的一种情况
- Android内存泄漏就这样产生了
- Android内存泄漏就这样产生了
- Android内存泄漏就这样产生了
- javascript中容易产生的内存泄漏
- 内存溢出和内存泄漏的区别,产生原因以及解决方案
- 关闭Tomcat时,产生“线程未关闭,出现内存泄漏”错误和"java.lang.IllegalStateException"
- Android内存泄漏产生的原因以及解决方案(OOM)
- Android:内存溢出和内存泄漏的区别、产生原因以及解决方案
- 内存溢出和内存泄漏的区别、产生原因以及解决方案