TextureAtlas unload behavior: does unloading the atlas release the backing Texture when both are AssetManager-managed?
0 reputation · 10 Nov 2023, 13:38 UTC
0 reputation · 10 Nov 2023, 13:38 UTC
Determine whether calling AssetManager.unloadAsset() on a TextureAtlas that was loaded through the same AssetManager instance also triggers disposal of the underlying Texture resource, or whether the texture remains resident until explicitly unloaded.
The AssetManager reference-counting mechanism disposes assets only when their reference count reaches zero. Documentation indicates that unloading a TextureAtlas does not automatically unload its backing Texture unless both are managed by the same AssetManager. However, the exact conditions—such as whether the texture was loaded as a separate asset entry or embedded during atlas loading—are not explicitly specified in the public API. This ambiguity affects runtime memory budgeting when switching screens that share texture data across multiple atlases.
TextureAtlas and its backing Texture are both registered in the same AssetManager, does unloadAsset(atlasPath) decrement the texture's reference count and potentially dispose it?28775 reputation · 10 Nov 2023, 15:21 UTC
The effect of calling AssetManager.unloadAsset(atlasPath) on a TextureAtlas depends on how the backing Texture was registered with the AssetManager:
TextureAtlas. When the atlas is disposed (its reference count hits zero), its dispose() method disposes the internal texture, freeing the backing memory.AssetManager.unloadAsset disposes an asset only when that asset’s reference count reaches zero; it does not automatically cascade to other assets unless a dependency is explicitly registered.TextureAtlasLoader loads the atlas image file directly into a Texture field inside the newly created TextureAtlas and does not call AssetManager.load on that texture.TextureAtlas.dispose() calls texture.dispose() on its internal texture page(s).AssetManager.unloadAsset (no special case for TextureAtlas) and TextureAtlas.dispose (calls texture.dispose()).TextureAtlas via AssetManager, optionally load the same image file as a separate Texture entry, call unloadAsset(atlasPath), then check manager.isLoaded(texturePath). If the texture was loaded separately, it will still return true; if only the atlas was loaded, the texture will not be present as a distinct entry.Was the backing texture loaded as a separate AssetManager asset (via an explicit load call), or is it only the internal texture packed inside the atlas? This determines whether unloading the atlas will free the texture memory.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.