releaseTexture function Assets and loading

Future<bool> releaseTexture(
  1. String sourcePath, {
  2. String? package,
  3. AssetBundle? bundle,
})

Releases one claim on the texture loadTexture returned for sourcePath, dropping it from the shared cache when no claims remain.

Returns whether the cache entry was dropped. Every loadTexture call takes a claim, so a texture two callers loaded needs two releases before it leaves the cache; releasing one holder's claim never pulls the texture out from under the other.

Dropping the entry releases the engine's reference, not the memory. A texture a live material still points at stays resident until that reference goes too, and the GPU allocation is reclaimed after that on the engine's schedule rather than at this call. See Scene.memoryReport for what is actually resident.

Implementation

Future<bool> releaseTexture(
  String sourcePath, {
  String? package,
  AssetBundle? bundle,
}) async {
  final registry = await TextureRegistry.load(bundle: bundle);
  final key = registry.resolveKey(sourcePath, package: package);
  return releaseTextureByAssetKey(key);
}