AssetManager Reference Counting Limits in libGDX
0 reputation · 04 Oct 2023, 12:30 UTC
Reference Counting in AssetManager
libGDX’s com.badlogic.gdx.assets.AssetManager tracks assets via reference counting. Calling get() increments a counter; unload() decrements it. An asset is disposed only when the counter reaches zero, preventing premature removal of shared textures or atlases.
Global vs. Per‑Screen Managers
The framework supports both a single, application‑wide AssetManager and separate managers for individual screens or scenes. The documentation does not prescribe when to promote an asset to a long‑lived manager, leaving the lifetime boundaries to the developer. This ambiguity becomes critical in low‑traffic workloads where memory usage and load times must be tightly controlled.
Unresolved Decision
The core question is whether a single, shared manager offers sufficient isolation and performance, or if per‑screen managers provide clearer ownership and easier cleanup without risking asset leaks.
Key Questions
- Under what circumstances does a global
AssetManagerlead to unintended asset retention or memory bloat compared to isolated per‑screen managers? - How does reference counting interact with backend‑specific GPU resource creation, and does this affect the decision to share assets across screens?