Frontory

Open code, practice, and notes →

Download source with English comments · for reading

Three.js · 23 Resource Ownership Ledger

Series contents · Technology map

Stage: Resource Lifetimes, Accessibility, and Measurement · Editable example · Storage ID: threejs-step-23

Goals and learning outcomes

Prerequisites

Prerequisite concepts: Offscreen Output, Restoring State. Prepare the result files and observation notes from unit 22.

Key concepts and explanations

Explicit Release

scene.remove only detaches an object from the scene. GPU-related resources of geometry,material,texture need separate dispose calls.

Shared Lifetimes

Multiple objects can use one resource. Record owners and reference scope so it is not released before its last user finishes.

Practice setup

First read the execution-scope guidance on the example screen. The following environment is for extending the assignment in a separate project. Implement it yourself in an HTML and ES module project served by a separate local HTTP development server. Pin three and addons to the same installed version and record it.

The linked example is a starting point. It does not implement every task below. Complete work beyond its supported scope in a separate project.

Practice tasks

  1. Prepare day-23.js and index.html in the external exercise project. Write a resourceTracker that tracks created geometry,material,texture in a Set.
  2. Remove only one of two Mesh objects sharing a material, keep the other rendering, and release each resource once at final shutdown.
  3. Save the output under the One user only input condition, then run again under the All users condition. Expected: Shared resources must be released after the last user finishes. Compare with the actual screen and logs, and record the actual result and reasons for any differences in day-23-notes.md.

Variables to observe

VariableBaselineChangeExpected change / hypothesis
Removal scopeOne user onlyAll usersShared resources must be released after the last user finishes.

Predictions in this table are not measured results. Change one condition at a time and record why the actual result differs.

Completion criteria

Self-check

  1. Does material.dispose automatically release textures too?
  2. What else should you check about the lifetime of glTF ImageBitmap objects?

Official references

Linked example and execution scope

Example source · Runtime environments and limits

This is an editable browser experiment. Measurements vary with the current device and browser.

Source code and records are not overwritten automatically. Resetting an existing example also preserves your notes.

Next learning

Previous: Render Targets and Minimap · Next: Asynchronous Scene Replacement

Open code, practice, and notes →