简体   繁体   English

javascript html5元素删除

[英]javascript html5 element remove

How do you remove a html element which is not in the DOM tree( stored in a separate structure) by JS 如何通过JS删除不在DOM树中的html元素(存储在单独的结构中)

I have a project where i make an audio request (html5) audio.src="someserver" Server long polls and sends the data to audio. 我有一个项目,我发出音频请求(html5)audio.src =“someserver”服务器长轮询并将数据发送到音频。 and audio plays it. 和音频播放它。

when audio is finished browser receives a command to stop the audio. 音频完成后,浏览器会收到停止音频的命令。

I store these audio elements in a hashtable in javascript and not in dom structure like standard html/ 我将这些音频元素存储在javascript中的哈希表中,而不是像标准html / dom结构那样存储在dom结构中

so remove parent/child does not apply. 所以删除父/子不适用。

as far as I know we dont even need to clean these objects as when there is no reference to that object, It should be deleted(internally) So is setting my audio element to NULL enough. 据我所知,我们甚至不需要清理这些对象,就像没有对该对象的引用一样,它应该被删除(内部)所以将我的音频元素设置为NULL就足够了。 ?

I am getting performance hits in my browser ? 我在浏览器中获得性能提升?

Also a reminder that when we make the audio request there are also 4-5 other longed polled requests. 还提醒一下,当我们发出音频请求时,还有4-5个其他渴望的轮询请求。

DOM nodes aren't much different than any other JS object. DOM节点与任何其他JS对象没有太大的不同。 If they don't have any references to them, they should get garbage collected. 如果他们没有任何参考,他们应该收集垃圾。

That said there may be implicit references. 也就是说可能存在隐含的引用。 If it's playing an audio file for instance the browser itself may have references to it in order maintain the player. 如果它正在播放音频文件,例如浏览器本身可能会引用它以便维护播放器。 So as long as the audio element is completely stopped and dereferenced, it should automatically get cleaned up. 因此,只要音频元素完全停止并取消引用,它就会自动清理。

I think you are over thinking this. 我想你是在想这个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM