Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Does this work any better?</p> <pre><code>mybutton.click(function() { var cloned = $('#audiotemplate').clone()[0]; cloned.play(); cloned.onended = function() { $(cloned).remove(); } }); </code></pre> <p><a href="http://jsfiddle.net/alexdickson/9WZHR/" rel="nofollow">Here on JSFiddle.</a></p> <p>I can only guess about the leak, and that is some memory is reserved for every instance you clone, and when it finishes it doesn't auto clean up because you may need to access it again. For example, your browser doesn't know you only want it played once, so it will keep it around, because you <em>may</em> want to call <code>play()</code> on it again.</p> <p>Using jQuery's <code>remove()</code> should free up that memory.</p> <h3>Update</h3> <p>How many times are you cloning it? You are aware this is a browser, and probably not optimised to have hundreds of <code>audio</code> elements being ran simultaneously?</p> <p>I just cloned it <del>~300</del> ~600 times in Firefox 3.6 and it ran fine. It did crash for me after a few hundred on Chrome 8 though.</p> <p><a href="http://jsfiddle.net/alexdickson/xz99K/" rel="nofollow">Here it is cloning via <code>setInterval()</code></a>. <strong>Do not click</strong> it if you think it will crash your browser.</p> <h3>Update</h3> <blockquote> <p>@alex: No, not simultaneously. My problem is that Chromium leaks memory even if the the sound is shorter than the respawn interval (as in Note 2) - so not playing at the same time, but after each other.</p> </blockquote> <p><a href="http://jsfiddle.net/alexdickson/4p2Jw/1/" rel="nofollow">Does this still crash your browsers?</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload