You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
webgpu: Investigate proper cleanup in GPUBuffer #45504
I thought maybe we could have trait LazyFinalize: Drop that would cause all such objects to be stored in some array and then dropped from outside. But the problem are subobjects (they might be dead) and realm might also be dead, so we might need to something else (prefinalizer hooks ideally -- are they equal to FinalizeRegistery?)
FinalizeCallbacks are post finalize, but I already considered this here: #42023 (comment) but the proposal is too limited.
Still we could use the idea of of subobjects. We need two stage GC finalize, so we can get it by two JS objects. First one is just proxy/wrapper for the second one. First one would present actual usage and would be GCed when there is no external references to it anymore. Second one would be permarooted, but the first finalizer would mark it for deletion (global array of such objects) and then outside of GC we would walk the array and do destroy (deteching buffers and stuff) and then unrooted them so next time GC is run it will finalize the second object.
The only problem here is that permaroots are footgun on their own.
When using NewExternalArrayBuffer one does not need to call DetachArrayBuffer as freeFunc will be called at GC. But one can still call DetachArrayBuffer to do like early destruction which will call freeFunc.
Activity
[-]webgpu: Investigate proper Cleanup in GPUBuffer[/-][+]webgpu: Investigate proper cleanup in GPUBuffer[/+]sagudev commentedon Jun 9, 2026
FinalizeCallbacks are post finalize, but I already considered this here: #42023 (comment) but the proposal is too limited.
Still we could use the idea of of subobjects. We need two stage GC finalize, so we can get it by two JS objects. First one is just proxy/wrapper for the second one. First one would present actual usage and would be GCed when there is no external references to it anymore. Second one would be permarooted, but the first finalizer would mark it for deletion (global array of such objects) and then outside of GC we would walk the array and do destroy (deteching buffers and stuff) and then unrooted them so next time GC is run it will finalize the second object.
The only problem here is that permaroots are footgun on their own.
sagudev commentedon Jul 9, 2026
I think one does not need detaching the buffer if one allocates it with https://searchfox.org/firefox-main/rev/0088392ab4ccab730743ed188ddec62d04e578b7/js/public/ArrayBuffer.h#177
sagudev commentedon Jul 9, 2026
I asked this on matrix and they said:
https://matrix.to/#/!CZEbuMfGYVdQMIBKeP:mozilla.org/$YQ1O-zde0nMcpdTt_RsXGetLKuJ0BrdzSDURKSt-rOE?via=mozilla.org&via=matrix.org&via=igalia.com
webgpu: Proper cleanup in GPUBuffer (servo#46415)