admin管理员组文章数量:1317729
Hi, I'm slowly making a chrome extension, and I need to parse some data that contains html entities, and I need to decode it. I saw in an answer here that I could use document.createElement
for it, so I did this:
htmlDecode: function(input) {
if(/[<>]/.test(input)) { // To avoid creating tags like <script> :s
return "Invalid Input";
}
var e = document.createElement('div');
e.innerHTML = input;
return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue;
}
However I'm worried that document.createElement
leaves elements behind because this function runs on the background script, so it's not like it gets refreshed often, and it runs around 35000 times every 5 minutes.
So, do elements created by document.createElement
get freed, or do they stay?
I mean, I do not append them anywhere and they are assiged to a local variable, but I'm not sure.
Hi, I'm slowly making a chrome extension, and I need to parse some data that contains html entities, and I need to decode it. I saw in an answer here that I could use document.createElement
for it, so I did this:
htmlDecode: function(input) {
if(/[<>]/.test(input)) { // To avoid creating tags like <script> :s
return "Invalid Input";
}
var e = document.createElement('div');
e.innerHTML = input;
return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue;
}
However I'm worried that document.createElement
leaves elements behind because this function runs on the background script, so it's not like it gets refreshed often, and it runs around 35000 times every 5 minutes.
So, do elements created by document.createElement
get freed, or do they stay?
I mean, I do not append them anywhere and they are assiged to a local variable, but I'm not sure.
- 2 Sure, nothing references the div anymore after the function is ran, so it will be eventually garbage-collected. – Bergi Commented Mar 10, 2013 at 11:33
1 Answer
Reset to default 8They will be garbage collected. In particular, since you're developing a Chrome extension, V8 tends to recycle temporaries like this very quickly so it shouldn't be much of a concern.
If you are worried about this in general, one mon solution is to simply keep a single div around to do the job.
本文标签: javascriptDo elements created with documentcreateElement stay in memoryStack Overflow
版权声明:本文标题:javascript - Do elements created with document.createElement stay in memory? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742021723a2414802.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论