
memory-management
Game memory optimization, object pooling, garbage collection tuning, and efficient resource management for target platforms.
- Installs
- 71
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/pluginagentmarketplace/custom-plugin-game-developer --skill memory-management- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads memory-management automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
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
// ✅ Production-Ready: Generic Object Pool
public class ObjectPool<T> where T : class
{
private readonly Stack<T> _pool;
private readonly Func<T> _createFunc;
private readonly Action<T> _onGet;
private readonly Action<T> _onReturn;
private readonly int _maxSize;
public int CountActive { get; private set; }
public int CountInPool => _pool.Count;
public ObjectPool(
Func<T> createFunc,
Action<T> onGet = null,
Action<T> onReturn = null,
int initialSize = 10,
int maxSize = 100)
{
_createFunc = createFunc;
_onGet = onGet;
_onReturn = onReturn;
_maxSize = maxSize;
_pool = new Stack<T>(initialSize);
// Pre-warm pool
for (int i = 0; i < initialSize; i++)
{
_pool.Push(_createFunc());
}
}
public T Get()
{
T item = _pool.Count > 0 ? _pool.Pop() : _createFunc();
_onGet?.Invoke(item);
CountActive++;
return item;
}
public void Return(T item)
{
if (item == null) return;
_onReturn?.Invoke(item);
CountActive--;
if (_pool.Count < _maxSize)
{
_pool.Push(item);
}
// If pool is full, let GC collect the item
}
public void Clear()
{
_pool.Clear();
CountActive = 0;
}
}
// Usage Example: Bullet Pool
public class BulletManager : MonoBehaviour
{
private ObjectPool<Bullet> _bulletPool;
void Awake()
{
_bulletPool = new ObjectPool<Bullet>(
createFunc: () => Instantiate(bulletPrefab).GetComponent<Bullet>(),
onGet: bullet => bullet.gameObject.SetActive(true),
onReturn: bullet => bullet.gameObject.SetActive(false),
initialSize: 50,
maxSize: 200
);
}
public Bullet SpawnBullet(Vector3 position, Vector3 direction)
{
var bullet = _bulletPool.Get();
bullet.Initialize(position, direction);
bullet.OnDestroyed += () => _bulletPool.Return(bullet);
return bullet;
}
}
Garbage Collection Optimization
GC SPIKE PREVENTION:
┌─────────────────────────────────────────────────────────────┐
│ AVOID IN UPDATE/HOT PATHS: │
│ ✗ new object() │
│ ✗ string concatenation ("a" + "b") │
│ ✗ LINQ queries (ToList(), Where(), etc.) │
│ ✗ Boxing value types │
│ ✗ Closures/lambdas capturing variables │
│ ✗ foreach on non-struct enumerators │
│ │
│ DO INSTEAD: │
│ ✓ Object pooling │
│ ✓ StringBuilder for strings │
│ ✓ Pre-allocated collections │
│ ✓ Struct-based data │
│ ✓ Cache delegates │
│ ✓ for loops with index │
└─────────────────────────────────────────────────────────────┘
// ✅ Production-Ready: Allocation-Free Patterns
public class AllocationFreePatterns
{
// ❌ BAD: Allocates every frame
void BadUpdate()
{
string status = "Health: " + health + "/" + maxHealth; // Allocates
var enemies = allEntities.Where(e => e.IsEnemy).ToList(); // Allocates
foreach (var enemy in enemies) { } // May allocate enumerator
}
// ✓ GOOD: Zero allocations
private StringBuilder _sb = new StringBuilder(64);
private List<Entity> _enemyCache = new List<Entity>(100);
void GoodUpdate()
{
// Reuse StringBuilder
_sb.Clear();
_sb.Append("Health: ").Append(health).Append("/").Append(maxHealth);
// Reuse list, avoid LINQ
_enemyCache.Clear();
for (int i = 0; i < allEntities.Count; i++)
{
if (allEntities[i].IsEnemy)
_enemyCache.Add(allEntities[i]);
}
// Index-based iteration
for (int i = 0; i < _enemyCache.Count; i++)
{
ProcessEnemy(_enemyCache[i]);
}
}
}
Memory Profiling
PROFILING WORKFLOW:
┌─────────────────────────────────────────────────────────────┐
│ 1. BASELINE: Measure memory at known state │
│ → Startup, menu, gameplay, level transition │
│ │
│ 2. MONITOR: Track over time │
│ → Memory growth indicates leaks │
│ → Spikes indicate heavy allocations │
│ │
│ 3. SNAPSHOT: Capture heap at suspicious moments │
│ → Compare snapshots to find what's growing │
│ │
│ 4. TRACE: Find allocation source │
│ → Stack trace shows where allocation happened │
│ → Identify hot paths │
│ │
│ 5. FIX: Apply optimization │
│ → Pool, cache, or eliminate allocation │
│ │
│ 6. VERIFY: Confirm fix worked │
│ → Re-profile same scenario │
└─────────────────────────────────────────────────────────────┘
PROFILING TOOLS:
┌─────────────────────────────────────────────────────────────┐
│ Unity: │
│ • Memory Profiler (Package) │
│ • Profiler window (Memory section) │
│ • Deep Profile mode │
│ │
│ Unreal: │
│ • Unreal Insights │
│ • memreport command │
│ • stat memory │
│ │
│ Native: │
│ • Valgrind (Linux) │
│ • Instruments (macOS) │
│ • Visual Studio Diagnostic Tools │
└─────────────────────────────────────────────────────────────┘
Asset Streaming
STREAMING STRATEGY:
┌─────────────────────────────────────────────────────────────┐
│ STREAMING ZONES │
│ │
│ [Loaded] [Loading...] [Unloaded] [Unloaded] │
│ ▲ ▲ │ │ │
│ │ │ │ │ │
│ ──────●───────────●────────────●────────────●────── │
│ Player Trigger Far Zone Very Far │
│ Position │
│ │
│ STREAMING RULES: │
│ • Load when player approaches (predictive) │
│ • Unload when player far away + timeout │
│ • Priority: Visible > Nearby > Background │
│ • Async loading to avoid hitches │
└─────────────────────────────────────────────────────────────┘
// ✅ Production-Ready: Asset Streaming Manager
public class StreamingManager : MonoBehaviour
{
[SerializeField] private float loadDistance = 50f;
[SerializeField] private float unloadDistance = 100f;
[SerializeField] private float unloadDelay = 5f;
private Dictionary<string, StreamingZone> _zones = new();
private Queue<AsyncOperation> _loadQueue = new();
void Update()
{
Vector3 playerPos = Player.Position;
foreach (var zone in _zones.Values)
{
float distance = Vector3.Distance(playerPos, zone.Center);
if (distance < loadDistance && !zone.IsLoaded)
{
StartCoroutine(LoadZoneAsync(zone));
}
else if (distance > unloadDistance && zone.IsLoaded)
{
StartCoroutine(UnloadZoneDelayed(zone, unloadDelay));
}
}
}
private IEnumerator LoadZoneAsync(StreamingZone zone)
{
zone.State = ZoneState.Loading;
var operation = SceneManager.LoadSceneAsync(zone.SceneName, LoadSceneMode.Additive);
operation.allowSceneActivation = false;
while (operation.progress < 0.9f)
{
yield return null;
}
operation.allowSceneActivation = true;
zone.State = ZoneState.Loaded;
}
}
🔧 Troubleshooting
┌─────────────────────────────────────────────────────────────┐
│ PROBLEM: Memory keeps growing over time (leak) │
├─────────────────────────────────────────────────────────────┤
│ DEBUG: │
│ → Take memory snapshots at intervals │
│ → Compare snapshots to find growing objects │
│ → Check for missing unsubscribes (events) │
│ → Look for collections that never clear │
├─────────────────────────────────────────────────────────────┤
│ SOLUTIONS: │
│ → Implement IDisposable pattern │
│ → Use weak references for caches │
│ → Clear collections when changing scenes │
│ → Unsubscribe from events in OnDestroy │
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ PROBLEM: GC causing frame spikes │
├─────────────────────────────────────────────────────────────┤
│ DEBUG: │
│ → Profile with GC.Alloc markers │
│ → Look for allocations in Update/FixedUpdate │
│ → Check for string operations in hot paths │
├─────────────────────────────────────────────────────────────┤
│ SOLUTIONS: │
│ → Implement object pooling │
│ → Use structs instead of classes where possible │
│ → Pre-allocate collections with known capacity │
│ → Spread GC across frames (incremental GC) │
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ PROBLEM: Out of memory on mobile │
├─────────────────────────────────────────────────────────────┤
│ DEBUG: │
│ → Check texture memory usage │
│ → Look for duplicate assets │
│ → Monitor during level transitions │
├─────────────────────────────────────────────────────────────┤
│ SOLUTIONS: │
│ → Reduce texture resolution │
│ → Implement aggressive streaming │
│ → Unload unused assets (Resources.UnloadUnusedAssets) │
│ → Use compressed texture formats │
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ PROBLEM: Hitches during level loading │
├─────────────────────────────────────────────────────────────┤
│ SOLUTIONS: │
│ → Use async loading (LoadSceneAsync) │
│ → Spread instantiation across frames │
│ → Pre-warm object pools during loading screen │
│ → Stream assets instead of loading all at once │
└─────────────────────────────────────────────────────────────┘
Memory Optimization Checklist
| Area | Technique | Impact | Effort |
|---|---|---|---|
| Objects | Object Pooling | High | Medium |
| Strings | StringBuilder | Medium | Low |
| Collections | Pre-allocation | Medium | Low |
| Assets | Streaming | High | High |
| Textures | Compression | High | Low |
| GC | Incremental GC | Medium | Low |
| Events | Weak References | Low | Medium |
Use this skill: When optimizing memory usage, reducing frame stutters, or supporting mobile platforms.
FAQ
What does the memory-management skill do?
Game memory optimization, object pooling, garbage collection tuning, and efficient resource management for target platforms.
How do I install memory-management?
Run npx skills add https://github.com/pluginagentmarketplace/custom-plugin-game-developer --skill memory-management in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/memory-management/ (personal) or .claude/skills/memory-management/ (project).
Which AI agents can use memory-management?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is memory-management safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains memory-management?
It is published by pluginagentmarketplace in pluginagentmarketplace/custom-plugin-game-developer. It has 71 recorded installs.
More from pluginagentmarketplace/custom-plugin-game-developer
game-design-theory
pluginagentmarketplace/custom-plugin-game-developer
Comprehensive game design theory covering MDA framework, player psychology, balance principles, and progression systems. Master why games are fun.
level-design
pluginagentmarketplace/custom-plugin-game-developer
Level design fundamentals, pacing, difficulty progression, environmental storytelling, and spatial design for engaging gameplay experiences.
gameplay-mechanics
pluginagentmarketplace/custom-plugin-game-developer
Open the skill to read its SKILL.md instructions.
daw-music
pluginagentmarketplace/custom-plugin-game-developer
Open the skill to read its SKILL.md instructions.
game-engines
pluginagentmarketplace/custom-plugin-game-developer
Open the skill to read its SKILL.md instructions.
particle-systems
pluginagentmarketplace/custom-plugin-game-developer
Open the skill to read its SKILL.md instructions.
Popular media & creative skills
hyperframes
heygen-com/hyperframes
Read first to make, edit, animate or render any video with HyperFrames (HTML rendered to video), including launch films, explainers, music videos, charts, maps, vertical clips, title cards, captions and overlays. Holds the render contract, the work loop and what each kind of video needs.
media-use
heygen-com/hyperframes
Get or make any media for a HyperFrames video - music, sound effects, images, icons, logos, voiceover, avatar and generated video, transcripts, cutouts, colour grades and looks - with HeyGen or free local tools, and mix placed audio. Also for footage that looks dark, flat or dull, or should be stylized or hidden.
hyperframes-registry
heygen-com/hyperframes
About 450 ready-made HyperFrames blocks and components installed as editable source - transitions, overlays, titles, kinetic type, captions, charts, map overlays, 3D, camera moves. Use it before hand-building any named visual (CRT scanlines, glitch, film grain, a chart); also for hyperframes add and catalog.
hyperframes-creative
heygen-com/hyperframes
Non-animation creative direction for HyperFrames videos. Use for design spec (frame.md / design.md) handling, palettes, typography, narration, beat planning, audio-reactive visuals, composition patterns, and brand / style decisions. For atomic motion patterns and scene blueprints, use hyperframes-animation.
ai-video-generation
101-skills/superpowers
Generate AI videos with Google Veo, Seedance 2.0, HappyHorse, Wan, Grok and 40+ models via inference.sh CLI. Models: Veo 3.1, Veo 3, Seedance 2.0, HappyHorse 1.0, Wan 2.5, Grok Imagine Video, OmniHuman, Fabric, HunyuanVideo. Capabilities: text-to-video, image-to-video, reference-to-video, video editing, lipsync, avatar animation, video upscaling, foley sound. Use for: social media videos, marketing content, explainer videos, product demos, AI avatars. Triggers: video generation, ai video, text to video, image to video, veo, animate image, video from image, ai animation, video generator, generate video, t2v, i2v, ai video maker, create video with ai, runway alternative, pika alternative, sora alternative, kling alternative, seedance, happyhorse
ai-image-generation
101-skills/superpowers
Generate AI images with GPT-Image-2, FLUX, Gemini, Grok, Seedream, Reve and 50+ models via inference.sh CLI. Models: GPT-Image-2, FLUX Dev LoRA, FLUX.2 Klein LoRA, Gemini 3 Pro Image, Grok Imagine, Seedream 4.5, Reve, ImagineArt. Capabilities: text-to-image, image-to-image, inpainting, LoRA, image editing, upscaling, text rendering. Use for: AI art, product mockups, concept art, social media graphics, marketing visuals, illustrations. Triggers: flux, image generation, ai image, text to image, stable diffusion, generate image, ai art, midjourney alternative, dall-e alternative, text2img, t2i, image generator, ai picture, create image with ai, generative ai, ai illustration, grok image, gemini image, gpt image, openai image, chatgpt image