Back to Content

GPUDevice: destroy() method

files/en-us/web/api/gpudevice/destroy/index.md

latest1.1 KB
Original Source

{{APIRef("WebGPU API")}}{{SecureContext_Header}}{{AvailableInWorkers}}

The destroy() method of the {{domxref("GPUDevice")}} interface destroys the device, preventing further operations on it.

Note that:

  • Any commands currently enqueued on the device's {{domxref("GPUQueue")}} will be executed before the device is destroyed.
  • Any WebGPU resources created using the device (buffers, textures, etc.) are also destroyed.
  • Any mapped buffers created using the device will be unmapped.

Syntax

js-nolint
destroy()

Parameters

None.

Return value

None ({{jsxref("undefined")}}).

Examples

js
async function init() {
  if (!navigator.gpu) {
    throw Error("WebGPU not supported.");
  }

  const adapter = await navigator.gpu.requestAdapter();
  if (!adapter) {
    throw Error("Couldn't request WebGPU adapter.");
  }

  let device = await adapter.requestDevice();

  // Some time later

  device.destroy();
}

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also