Skip to content

material#retain

Summary

material#retain adds an ownership reference to a shared material. Retain once for each additional mesh that will own the material. Each mesh releases its own reference on destruction.

Syntax

Material.retain(): this
Material.release(): void
const shared = material.retain();

Returns

this - The same material from retain(). A material starts with one reference. release() relinquishes one reference and frees the material's owned resources when the last reference is released. Retaining or releasing a fully released material throws.

Example

const material = wgpu.material.unlit();
const left = wgpu.createMesh(wgpu.geometry.box(), material);
const right = wgpu.createMesh(wgpu.geometry.box(), material.retain());
left.destroy();
right.destroy();

See Also