| name | memory-management |
| version | 2.0.0 |
| description | Game memory optimization, object pooling, garbage collection tuning,
and efficient resource management for target platforms.
|
| sasmp_version | 1.3.0 |
| bonded_agent | 02-game-programmer |
| bond_type | PRIMARY_BOND |
| parameters | [{"name":"platform","type":"string","required":false,"validation":{"enum":["pc","console","mobile","vr","web"]}},{"name":"issue_type","type":"string","required":false,"validation":{"enum":["leak","fragmentation","gc_spikes","budget_exceeded"]}}] |
| retry_policy | {"enabled":true,"max_attempts":3,"backoff":"exponential"} |
| observability | {"log_events":["start","complete","error","gc_collect"],"metrics":["heap_size_mb","gc_time_ms","allocation_rate","pool_usage"]} |
Memory Management
Memory Architecture
┌─────────────────────────────────────────────────────────────┐
│ GAME MEMORY LAYOUT │
├─────────────────────────────────────────────────────────────┤
│ STACK (Fast, Auto-managed): │
│ ├─ Local variables │
│ ├─ Function parameters │
│ └─ Return addresses │
│ │
│ HEAP (Slower, Manual/GC-managed): │
│ ├─ Dynamic allocations (new/malloc) │
│ ├─ Game objects │
│ └─ Asset data │
│ │
│ STATIC (Fixed at compile time): │
│ ├─ Global variables │
│ ├─ Static class members │
│ └─ Constant data │
│ │
│ VRAM (GPU Memory): │
│ ├─ Textures │
│ ├─ Meshes │
│ └─ Render targets │
└─────────────────────────────────────────────────────────────┘
Platform Memory Budgets
MEMORY BUDGET GUIDELINES:
┌─────────────────────────────────────────────────────────────┐
│ PLATFORM │ TOTAL │ GAME LOGIC │ ASSETS │ BUFFER │
├────────────────┼──────────┼────────────┼──────────┼────────┤
│ Mobile Low │ 512 MB │ 50 MB │ 350 MB │ 112 MB │
│ Mobile High │ 2 GB │ 200 MB │ 1.5 GB │ 300 MB │
│ Console │ 8 GB │ 500 MB │ 6 GB │ 1.5 GB │
│ PC Min │ 4 GB │ 300 MB │ 3 GB │ 700 MB │
│ PC High │ 16 GB │ 1 GB │ 12 GB │ 3 GB │
│ VR │ 8 GB │ 400 MB │ 6 GB │ 1.6 GB │
└────────────────┴──────────┴────────────┴──────────┴────────┘
VRAM BUDGETS:
┌─────────────────────────────────────────────────────────────┐
│ Mobile: 512 MB - 1 GB │
│ Console: 8-12 GB (shared with RAM) │
│ PC Low: 2-4 GB │
│ PC High: 8-16 GB │
└─────────────────────────────────────────────────────────────┘
Object Pooling
public class ObjectPool<T> where :
{
Stack<T> _pool;
Func<T> _createFunc;
Action<T> _onGet;
Action<T> _onReturn;
_maxSize;
CountActive { ; ; }
CountInPool => _pool.Count;
{
_createFunc = createFunc;
_onGet = onGet;
_onReturn = onReturn;
_maxSize = maxSize;
_pool = Stack<T>(initialSize);
( i = ; i < initialSize; i++)
{
_pool.Push(_createFunc());
}
}
{
T item = _pool.Count > ? _pool.Pop() : _createFunc();
_onGet?.Invoke(item);
CountActive++;
item;
}
{
(item == ) ;
_onReturn?.Invoke(item);
CountActive--;
(_pool.Count < _maxSize)
{
_pool.Push(item);
}
}
{
_pool.Clear();
CountActive = ;
}
}
:
{
ObjectPool<Bullet> _bulletPool;
{
_bulletPool = ObjectPool<Bullet>(
createFunc: () => Instantiate(bulletPrefab).GetComponent<Bullet>(),
onGet: bullet => bullet.gameObject.SetActive(),
onReturn: bullet => bullet.gameObject.SetActive(),
initialSize: ,
maxSize:
);
}
{
bullet = _bulletPool.Get();
bullet.Initialize(position, direction);
bullet.OnDestroyed += () => _bulletPool.Return(bullet);
bullet;
}
}