FlixelAssetMode
View sourceenum
org.flixelgdx.asset.FlixelAssetMode
Controls when the asset manager reclaims memory for non-persistent assets.
The active mode is read by Flixel.switchState and by individual asset handles on every FlixelAsset.release() call, so changing the mode mid-session takes effect immediately without any extra steps.
Set the mode on FlixelAssetManager via FlixelAssetManager.setAssetMode(FlixelAssetMode).
Choosing a mode
- FlixelAssetMode.LAZY - simplest; assets accumulate. Use when memory is not a concern or when you preload everything up front and rarely switch states.
- FlixelAssetMode.STANDARD - safe default; mirrors how most 2D frameworks manage assets. The right choice for most games.
- FlixelAssetMode.AGGRESSIVE - tightest footprint. Use when you have many short-lived states and memory pressure is real. Read the FlixelAssetMode.AGGRESSIVE docs carefully before opting in.
Fields
LAZY
Assets are never automatically unloaded. Every asset loaded into the manager stays in memory for the entire session, regardless of state switches or reference counts.
Equivalent to setting persist = true globally. FlixelAssetManager.clearNonPersist() is skipped entirely on state switches, so no teardown cost is paid at all.
Best for games that preload everything up front or have very few, long-lived states.
STANDARD
Non-persistent assets with a zero reference count are unloaded when Flixel.switchState runs. This is the default.
Persistent assets (see FlixelAsset.isPersist()) and any asset still held by a live object (reference count greater than zero) are kept across the switch.
AGGRESSIVE
Non-persistent assets are unloaded immediately the moment their reference count reaches zero, without waiting for a state switch.
This uses O(1) work per FlixelAsset.release() call - there is no periodic scan. The asset handle that just dropped to zero triggers the unload inline, then the handle is evicted from the manager cache so subsequent FlixelAssetManager.get(String) calls create a fresh handle.
Important caveats:
- FlixelAsset.release() must be called on the GL/render thread. Calling it from a background thread while libGDX may be uploading or disposing GPU resources is not safe in AGGRESSIVE mode. It is fine in LAZY and STANDARD since those only unload at state switch boundaries, which is always on the GL thread.
- After an aggressive eviction, the underlying libGDX asset is disposed. Any code that still holds a raw reference to the same
Texture(or other resource) object will encounter a disposed object. The automated sprite pipeline (loadGraphicanddestroy) handles this correctly; direct raw-asset usage outside that pipeline must ensure no other references remain before releasing. - Re-requesting an aggressively evicted asset requires calling FlixelAssetManager.load(String) again and awaiting the async load cycle.
Flixel.switchState still calls FlixelAssetManager.clearNonPersist() as a safety net for assets that were loaded but never retained.