Skip to content

Remove drop implementaiton for GPUBuffer #44640

Closed

Description

@jdm

Per #26488 we have an exemption for the current Drop implementation, but we want to remove it:

#36897 is an attempt to do this but it relies on interacting with a Promise from the new Drop implementation, which is unsafe when the JS context is shutting down.

Activity

  1. added
    A-content/bindings
    I-safety
    on Apr 30, 2026
  2. sagudev commented on Jul 1, 2026

    @sagudev
    Member

    There is also

    impl Drop for DataView {
    #[expect(unsafe_code)]
    fn drop(&mut self) {
    let cx = GlobalScope::get_cx();
    assert!(unsafe {
    js::jsapi::DetachArrayBuffer(*cx, self.buffer.underlying_object().handle())
    , but I am starting to wonder do we need to actually call DetachArrayBuffer if arraybuffer will be GCed (or is it permarooted in SM somehow? I doubt).

  3. sagudev commented on Jul 9, 2026

    @sagudev
    Member

    There is also

    servo/components/script/dom/bindings/buffer_source.rs

    Lines 1035 to 1040 in bda3700
    impl Drop for DataView {
    #[expect(unsafe_code)]
    fn drop(&mut self) {
    let cx = GlobalScope::get_cx();
    assert!(unsafe {
    js::jsapi::DetachArrayBuffer(*cx, self.buffer.underlying_object().handle())
    , but I am starting to wonder do we need to actually call DetachArrayBuffer if arraybuffer will be GCed (or is it permarooted in SM somehow? I doubt).

    GPUBuffer does not have a drop anymore, but DataView still has. But that is tracked in #45504

  4. jdm commented on Jul 9, 2026

    @jdm
    MemberAuthor

    Not true:

    impl Drop for GPUBuffer {
    fn drop(&mut self) {
    if let Err(e) = self
    .channel
    .0
    .send(WebGPURequest::DropBuffer(self.buffer.0))
    {
    error!(
    "Failed to send WebGPURequest::DropBuffer({:?}) ({}) - Potential leak",
    self.buffer.0, e
    );
    }
    }
    }

    We should move that to the Droppable pattern from other types and remove

  5. reopened this on Jul 9, 2026
  6. sagudev commented on Jul 9, 2026

    @sagudev
    Member

    Right

  7. self-assigned this
    on Jul 9, 2026
  8. added a commit that references this issue on Jul 15, 2026
    ba00cbe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-content/bindingsI-safety

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions