惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Schneier on Security
F
Fortinet All Blogs
B
Blog
GbyAI
GbyAI
P
Proofpoint News Feed
量子位
The Register - Security
The Register - Security
宝玉的分享
宝玉的分享
大猫的无限游戏
大猫的无限游戏
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
B
Blog RSS Feed
WordPress大学
WordPress大学
Recorded Future
Recorded Future
Recent Announcements
Recent Announcements
V
Vulnerabilities – Threatpost
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Secure Thoughts
雷峰网
雷峰网
Stack Overflow Blog
Stack Overflow Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Webroot Blog
Webroot Blog
AWS News Blog
AWS News Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
The GitHub Blog
The GitHub Blog
爱范儿
爱范儿
O
OpenAI News
月光博客
月光博客
H
Hacker News: Front Page
S
Security Affairs
W
WeLiveSecurity
The Hacker News
The Hacker News
aimingoo的专栏
aimingoo的专栏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Help Net Security
Help Net Security
MongoDB | Blog
MongoDB | Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
Docker
T
The Blog of Author Tim Ferriss
Spread Privacy
Spread Privacy
Blog — PlanetScale
Blog — PlanetScale
J
Java Code Geeks
S
Securelist
Microsoft Azure Blog
Microsoft Azure Blog
TaoSecurity Blog
TaoSecurity Blog
T
Threat Research - Cisco Blogs
M
MIT News - Artificial intelligence
A
About on SuperTechFans

博客园 - dail

IE浏览器在虚拟机中无法正常显示字符 jQuery在updatepanel中使用造成内存泄露 jQuery 1.7的隐藏改动 在javascript中实现类似asp.net webcontrol中的render的方法 jQuery 1.6的变化 jQuery ui effects - dail jQuery ui 1.8.6 position 的一个bug 一个progressbar widget jQuery编写widget的一些窍门 jquery animate动画的特殊用法。 一个简单的widget Jquery ui widget中的_create(),_init(),destroy() Jquery ui widget开发 Jquery ui css framework jquery animate Json.net简单用法 EXTJS学习(二)Message EXTJS学习(一) jquery+linq制作博客(二)
在使用jQuery的时候不小心的内存泄漏
dail · 2012-04-08 · via 博客园 - dail

在写chart widget的时候,我们使用了第三方的svg类库Raphael。结果客户给我们报了一个内存泄漏的bug,我们在测试的时候确实存在内存泄漏。经过测试发现了问题的原因。Raphael本身存在一些问题,还有就是在和jQuery使用的时候,我们也没有注意到一个问题。

在创建jQuery对象的时候,jQuery会将jQuery缓存起来,放到jQuery.cache对象中。在调用jQuery的remove方法的时候,会清理掉jQuery的缓存。我们的问题就出在这里,在Raphael中,自己有remove方法来清楚Raphael创建的raphael对象和svg/vml元素。而在chart中,我们会使用jQuery在raphael创建的svg/vml元素上。这样在调用raphael的remove方法的时候,就不能移除jQuery缓存。由此造成了对象一直保留内存中。

在Raphael中,自己的animate和remove方法也存在说明,就是在animate的时候,会创建animate需要的一些对象缓存到raphael对象中,在调用stop方法的时候会清理掉这些元素。而当remove的时候,仅仅做了remove的事情,并没有移除掉这些对象。而在文档中也没有提到需要注意的问题。我们在使用的时候,就没有注意到正在做动画的元素在remove的时候直接调用remove方法,没有在之前调stop。这样也造成了对象不能销毁。

上述两个问题是造成内存泄漏的主要原因。在试用jQuery的时候,如果要删除dom对象的话,最好采用jQuery的remove方法,否则可能会出现诸如我们那样的问题。在jQuery的remove方法中还会清楚掉时间绑定等信息。