Bug 95757 - AudioContext is never destructed.
Summary: AudioContext is never destructed.
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Audio (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Kentaro Hara
Depends on:
Reported: 2012-09-04 10:42 PDT by Pavel Podivilov
Modified: 2012-12-12 14:31 PST (History)
8 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Pavel Podivilov 2012-09-04 10:42:03 PDT
I just noticed that V8AudioContext::constructorCallback in V8AudioContextCustom.cpp leaks the pointer to AudioContext.
Shouldn't it also call V8DOMWrapper::setJSWrapperForActiveDOMObject to deref AudioContext in JS wrapper weak callback? Looks like currently all AudioContexts live forever.
Comment 1 Kentaro Hara 2012-09-04 17:38:55 PDT
I'll take a look.
Comment 2 Pavel Podivilov 2012-09-05 00:30:55 PDT
There is another problem with this code. After fixing the leak, you'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.
Comment 3 michaelbraithwaite 2012-11-09 03:19:05 PST
Would this explain why we hit the exception "audio resources unavailable for AudioContext construction" 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'll bug it, though I think in part its a spec issue with the lack of 'destroy' 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 'apps' run on it the life time model doesn't seem great. You can see this on https://turbulenz.com/ if you keep reloading some of the games.
Comment 4 Chris Rogers 2012-11-09 10:26:52 PST
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'll have a look at your case...
Comment 5 Chris Rogers 2012-12-12 14:31:02 PST
I believe this was fixed in: