Skip to main content

FlixelAssetMode

View source

enum

org.flixelgdx.asset.FlixelAssetMode

public final enum 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

Fields

LAZY

public static final FlixelAssetMode 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

public static final FlixelAssetMode 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

public static final FlixelAssetMode 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 (loadGraphic and destroy) 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.


Methods

values()

public static FlixelAssetMode[] values()

valueOf(String)

public static FlixelAssetMode valueOf(String name)