<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>95757</bug_id>
          
          <creation_ts>2012-09-04 10:42:03 -0700</creation_ts>
          <short_desc>AudioContext is never destructed.</short_desc>
          <delta_ts>2012-12-12 14:31:02 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Web Audio</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Pavel Podivilov">podivilov</reporter>
          <assigned_to name="Kentaro Hara">haraken</assigned_to>
          <cc>abarth</cc>
    
    <cc>crogers</cc>
    
    <cc>eric.carlson</cc>
    
    <cc>esprehn</cc>
    
    <cc>haraken</cc>
    
    <cc>jer.noble</cc>
    
    <cc>kbr</cc>
    
    <cc>michaelbraithwaite</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>711217</commentid>
    <comment_count>0</comment_count>
    <who name="Pavel Podivilov">podivilov</who>
    <bug_when>2012-09-04 10:42:03 -0700</bug_when>
    <thetext>I just noticed that V8AudioContext::constructorCallback in V8AudioContextCustom.cpp leaks the pointer to AudioContext.
Shouldn&apos;t it also call V8DOMWrapper::setJSWrapperForActiveDOMObject to deref AudioContext in JS wrapper weak callback? Looks like currently all AudioContexts live forever.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>711603</commentid>
    <comment_count>1</comment_count>
    <who name="Kentaro Hara">haraken</who>
    <bug_when>2012-09-04 17:38:55 -0700</bug_when>
    <thetext>I&apos;ll take a look.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>711791</commentid>
    <comment_count>2</comment_count>
    <who name="Pavel Podivilov">podivilov</who>
    <bug_when>2012-09-05 00:30:55 -0700</bug_when>
    <thetext>There is another problem with this code. After fixing the leak, you&apos;ll get debug crash in AudioContext::uninitialize.

Here is why. ScriptExecutionContext::stopActiveDOMObjects is called twice on navigation, first time from Document::detach and then from FrameLoader. As a result AudioContext::stop is also called twice.
First AudioContext::uninitialize deletes the AudioContext object. Then AudioContext::uninitialize is called again, but AudioContext is already destructed.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>762789</commentid>
    <comment_count>3</comment_count>
    <who name="">michaelbraithwaite</who>
    <bug_when>2012-11-09 03:19:05 -0800</bug_when>
    <thetext>Would this explain why we hit the exception &quot;audio resources unavailable for AudioContext construction&quot; so often? The 4 AudioContext limit gets exhausted even though at most one is currently active. I assumed there is no guarantee the unused ones will be garbage collected in any event.

As this is in V8*.cpp is this only in Chrome? Safari hits the same issue. 

If it is a separate issue I&apos;ll bug it, though I think in part its a spec issue with the lack of &apos;destroy&apos; method on the JavaScript AudioContext. If it is a finite resource and given when gc gets invoked is not controllable from JavaScript it means sometimes it fails which means users get no audio (or an broken app). For a single page web app where multiple &apos;apps&apos; run on it the life time model doesn&apos;t seem great. You can see this on https://turbulenz.com/ if you keep reloading some of the games.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>763143</commentid>
    <comment_count>4</comment_count>
    <who name="Chris Rogers">crogers</who>
    <bug_when>2012-11-09 10:26:52 -0800</bug_when>
    <thetext>The AudioContext releases its resources in AudioContext::uninitialize(), not in the destructor, so delayed garbage collection is not likely to be the issue.

Michael, I&apos;ll have a look at your case...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>789924</commentid>
    <comment_count>5</comment_count>
    <who name="Chris Rogers">crogers</who>
    <bug_when>2012-12-12 14:31:02 -0800</bug_when>
    <thetext>I believe this was fixed in:
http://trac.webkit.org/changeset/135152</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>