Resource Lifetimes

What the engine's shared caches keep, what they hand out, and which long-lived objects hold those handles. A cache can release an entry only once nothing holds a strong reference or borrowed pointer to it.

Caches

CacheKeepsHands outReleases
Resources animationsEach decoded SkeletalAnimation, by asset path, as an ArcBorrowed &SkeletalAnimation for in-call use; Arc for holdersNever, though holders share ownership
ScenePackages decoded materials (scene/src/scene_packages.rs)Each SceneMaterial by key as an Arc<SceneMaterial>, plus a HashMap<usize, Weak<SceneMaterial>> address indexArc<SceneMaterial> leases and borrowed referencesUnleased entries after a level change (Material eviction)
ScenePackages material definitionsParsed definitions keyed by record setInternalNever
ScenePackages procedural textures, animation primes, sequences, switchesArc valuesArcNever (holders share ownership)
ScenePackages far landmark models & impostorsWeak<dyn Any + Send + Sync> entriesArc<dyn Any + Send + Sync>Automatically when the last Arc holder drops

The entries that release themselves are the Weak caches and texture pixel buffers; decoded materials that no holder leases are evicted after a level change. Every other cache keeps its entries for its own lifetime.

Holders of Leases and References

Long-lived owners that retain handles beyond a single call:

  • Level records — World level records are read from converted files and keep no source package object; scene visibility keeps its level geometry, and reflected object sets keep their own images.
  • Animations — Each animated pawn, attached part with its own animation, and animated prop holds an Arc lease to its animation.
  • Materials — Leased by level mesh parts, emitter particles, decoration layers, far terrain tile landmarks and water, far scenery groups, and sky bodies (sun, moon, lens flare). In a game host: pawn models with held items, kept LOD levels, and mesh actors. Props that resolve through ScenePackages caches living as long as they do need no extra lease.
  • Address-keyed maps — Any map keyed by a material's pointer address outlives single calls and would alias a reused address after eviction; each such map is cleared of evicted addresses during eviction.
  • Geometry — Scene geometry views reference storage owned by the draw's owner (level draw data, pawn model streams, far tile); they hold no cache reference.

Material Eviction

ScenePackages drops each decoded SceneMaterial held only by the cache (Arc::strong_count == 1) that was already unleased on the previous eviction pass — so an entry is released after two consecutive passes without an external holder. Eviction clears parsed definitions' resolved slots pointing at evicted materials so the next lookup decodes them again, and returns evicted addresses so address-keyed caches (such as generated coordinate tables) can remove them.

A host schedules material eviction after applying a level change once the renderer has retired departed draws, and under memory pressure (SDL_EVENT_LOW_MEMORY) runs two passes so unleased entries are freed without waiting for a level transition. Texture pixel buffers are released separately.

Level loads run on 8 MiB worker threads because deeply recursive material graphs can exceed small default worker thread stacks when re-decoding after eviction.

Animations are not evicted.