1

How do you remove a html element which is not in the DOM tree( stored in a separate structure) by JS

I have a project where i make an audio request (html5) audio.src="someserver" Server long polls and sends the data to audio. 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/

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. ?

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

1 回答 1

4

DOM nodes aren't much different than any other JS object. 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.

于 2012-10-31T00:41:43.820 回答