playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
31 lines (30 loc) • 574 B
JavaScript
class RefCountedCache {
cache = /* @__PURE__ */ new Map();
destroy() {
this.cache.forEach((refCount, object) => {
object.destroy();
});
this.cache.clear();
}
incRef(object) {
const refCount = (this.cache.get(object) || 0) + 1;
this.cache.set(object, refCount);
}
decRef(object) {
if (object) {
let refCount = this.cache.get(object);
if (refCount) {
refCount--;
if (refCount === 0) {
this.cache.delete(object);
object.destroy();
} else {
this.cache.set(object, refCount);
}
}
}
}
}
export {
RefCountedCache
};