1. Dashboard
  2. Getting Started
  3. GitHub
  4. API
  5. Articles
  6. Level Editor
  7. Members
    1. Recent Activity
    2. Users Online
    3. Staff
    4. Search Members
  8. Forum
  9. Discord
  • Login
  • Register
  • Search
Getting Started
  • Everywhere
  • Getting Started
  • Articles
  • Pages
  • Forum
  • More Options
  1. GFX-Engine
  2. Articles
  3. Getting Started

Asset Management & Resource Lifetime

  • Andy
  • January 4, 2026 at 12:55 AM
  • 280 Views
  • 0 Comments

This article explains how assets, CPU/GPU memory, and resource ownership are handled in GFX-Next. It describes the complete lifecycle of resources, from loading and initialization to usage, synchronization, and eventual release. Special attention is given to how data is transferred between CPU and GPU memory, how ownership and access rules are defined, and how GFX-Next avoids common pitfalls such as memory leaks, race conditions, and redundant uploads. By clarifying these mechanisms, the article enables developers to manage resources efficiently, write performance-conscious code, and maintain a clear mental model of how data flows through the rendering and execution pipeline.

Contents [hideshow]
  1. What Is an Asset?
  2. The AssetManager
  3. Loading Assets
  4. Procedural Assets
  5. Asset Initialization (GPU Upload)
    1. Important
  6. CPU vs GPU Lifetime
    1. Why this matters
  7. User-Controlled Resource Policy
  8. Selective CPU Memory Freeing
  9. Asset Lifetime vs Scene Lifetime
  10. Asset Disposal (GPU Cleanup)
  11. Summary

The asset system is designed to:

  • make ownership explicit
  • separate CPU and GPU lifetime
  • work identically in runtime and editor
  • avoid hidden memory management

1. What Is an Asset?

In GFX-Next, an asset is any reusable resource that may:

  • be shared across multiple objects
  • live longer than a single scene
  • own GPU and/or CPU memory

Examples:

  • Mesh
  • StaticMeshModel
  • SkinnedMeshModel
  • Material
  • Shader
  • Texture
  • ComputeShader

Assets are not scene-owned.
They are managed globally by the AssetManager.

2. The AssetManager

The AssetManager is responsible for:

  • loading assets from disk
  • storing assets by type and identifier
  • initializing GPU resources
  • freeing CPU-side data
  • disposing GPU resources
C#
AssetManager assets = new AssetManager();

Assets can be:

  • loaded from disk
  • created procedurally
  • reused and shared freely

3. Loading Assets

Assets are usually loaded during LoadContent.

C#
_lionModel = assets.Load<StaticMeshModel>("Ressources/Lion/Lion.gltf");

Key properties:

  • assets are cached automatically
  • loading the same asset twice returns the same instance
  • the asset manager owns the instance

This makes asset usage cheap and predictable.

4. Procedural Assets

Not all assets come from disk.
Procedural assets are created in code and registered manually.

C#
_cubeMesh = assets.Add<Mesh>("CubeMesh", Cube.GetMesh(defaultMaterial));

This is commonly used for:

  • primitives
  • debug geometry
  • editor-only helpers
  • generated meshes

5. Asset Initialization (GPU Upload)

Assets that interact with the GPU implement IGraphicsResource.

C#
assets.InitializeAssets(RenderDevice);

This step:

  • uploads buffers
  • creates textures
  • compiles shaders
  • prepares render data

Important

Assets exist before GPU initialization.
This allows:

  • editor previews
  • asset inspection
  • serialization without a graphics context

6. CPU vs GPU Lifetime

GFX-Next explicitly separates:

  • CPU-side data
  • GPU-side data

After GPU upload, CPU data may no longer be needed.

C#
assets.FreeCPUResources();

Examples of CPU data:

  • vertex arrays
  • index buffers
  • animation data
  • imported mesh data

Why this matters

  • reduces memory usage
  • improves cache behavior
  • makes lifetime decisions explicit

The engine never frees CPU memory automatically.
This is a conscious design decision.

7. User-Controlled Resource Policy

Whether CPU memory is freed is entirely up to the user. The Game class contains the following property:

C#
public bool FreeCPUResources { get; set; } = true;

This allows different workflows:

Use CaseCPU Data
Runtime gameFree CPU memory
EditorKeep CPU memory
Procedural toolsMixed
DebuggingKeep CPU memory

There is no hidden behavior.

8. Selective CPU Memory Freeing

The asset manager supports type-based CPU cleanup.

C#
assets.FreeCPUResources<StaticMeshModel>();
assets.FreeCPUResources<SkinnedMeshModel>();

This allows:

  • freeing heavy imported data
  • keeping procedural meshes
  • editor-safe workflows

This can only be done if you disable the FreeCPUResources property and call them within the Initialize() function or later.

9. Asset Lifetime vs Scene Lifetime

Assets:

  • live independently of scenes
  • can be reused across scenes
  • are not destroyed when a scene is destroyed

Scenes only reference assets; they never own them.

This makes scene switching cheap and safe.

10. Asset Disposal (GPU Cleanup)

When the application shuts down:

C#
assets.DisposeAssets(RenderDevice);
assets.ClearAssets();

This:

  • releases GPU buffers
  • deletes textures
  • destroys shaders
  • clears asset references

No implicit disposal occurs during runtime.

Summary

The asset system in GFX-Next is built around:

  • explicit ownership
  • manual lifetime control
  • clear CPU/GPU separation
  • editor and runtime parity
  • zero hidden memory management

This design favors control and predictability over convenience.

  • Previous Article Scene & Gameplay
  • Next Article Meshes, Primitives & Materials

Categories

  1. Advanced Tutorial 1
  2. Getting Started 8
  3. Default Category 1
  4. Reset Filter

Partner & Supporter

  1. Privacy Policy
  2. Legal Notice
Powered by WoltLab Suite™