Skip to content
Back to skills

Managing Memory

ASecurity

Use when deciding how memory is allocated, owned, and freed in manual-memory code, in any language. Triggers on caller-provided buffers, arena, bump or linear allocators, object pools, free lists, virtual-memory reserve/commit, scratch allocators, object lifetimes, single ownership and borrowing, leaks, use-after-free, double-free, even when the user doesn't say 'memory' or 'allocator'.

  • 6 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 30, 2026
ai-agentsgoapi

Works with

  • api

Security analysis

A100/100

Pro scans all 9 files and shows the line behind each finding

Scanned November 30, 2026

npx -y skills add xonovex/platform --skill managing-memory --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Managing Memory?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Managing Memory
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/xonovex-managing-memory/badge)](https://www.skillsdirectory.com/skills/xonovex-managing-memory)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: managing-memory
description: "Use when deciding how memory is allocated, owned, and freed in manual-memory code, in any language. Triggers on caller-provided buffers, arena, bump or linear allocators, object pools, free lists, virtual-memory reserve/commit, scratch allocators, object lifetimes, single ownership and borrowing, leaks, use-after-free, double-free, even when the user doesn't say 'memory' or 'allocator'."
---

# Memory Management Guidelines

General principles for allocating, owning, and freeing memory in manual-memory or buffer-passing code. Language-agnostic; examples are in C. Domain skills (e.g. C99, GPU device memory) keep their own specifics and link here for the underlying principle.

## Essentials

- **Caller owns memory** - APIs take caller-provided storage; never allocate internally, see [references/caller-owns-memory.md](references/caller-owns-memory.md)
- **Group by lifetime** - Allocate together what dies together; free as a unit, see [references/ownership-and-lifetimes.md](references/ownership-and-lifetimes.md)
- **One owner** - Exactly one owner frees; everyone else borrows, see [references/ownership-and-lifetimes.md](references/ownership-and-lifetimes.md)

## Allocation strategy

- **Arena / bump** - Pointer-bump from a block; reset frees everything at once, see [references/arenas-and-pools.md](references/arenas-and-pools.md)
- **Object pool** - Fixed-size slots + free list; O(1) alloc/free, stable, see [references/arenas-and-pools.md](references/arenas-and-pools.md)
- **Scratch / temp** - Per-frame/per-request arena reset each cycle, see [references/arenas-and-pools.md](references/arenas-and-pools.md)
- **Virtual-memory reserve/commit** - Reserve a large range, commit pages on demand; stable addresses, no realloc copy, see [references/arenas-and-pools.md](references/arenas-and-pools.md)
- **Virtual-memory tricks** - Cap-free arrays, page-aligned growth, gapless ring buffers, end-of-page bounds checks, see [references/virtual-memory.md](references/virtual-memory.md)

## Ownership

- **Lifetime by scope** - Tie allocation lifetime to a clear scope/phase, see [references/ownership-and-lifetimes.md](references/ownership-and-lifetimes.md)
- **Handles over pointers** - Reference relocatable storage by index/handle (layout detail in **applying-data-oriented-design**), see [references/ownership-and-lifetimes.md](references/ownership-and-lifetimes.md)

## Gotchas

- Bump allocation has no bounds safety unless you check capacity; always assert/return on overflow.
- Two owners means double-free or leak; decide ownership explicitly, don't infer it.
- Pointers into a growing/reset allocation dangle. Prefer offsets/handles across a boundary (a virtual-memory reserve/commit block is the exception: it never moves).

## Progressive Disclosure

- Read [references/caller-owns-memory.md](references/caller-owns-memory.md) - Load when designing an API's allocation boundary or a non-allocating library
- Read [references/arenas-and-pools.md](references/arenas-and-pools.md) - Load when choosing an allocator: arena, pool, scratch, or virtual-memory backed
- Read [references/virtual-memory.md](references/virtual-memory.md) - Load when using address-space reservation for cap-free arrays, ring buffers, page-aligned growth, or end-of-page bounds checking
- Read [references/ownership-and-lifetimes.md](references/ownership-and-lifetimes.md) - Load when deciding who owns/frees memory and how long it lives

Files in this skill

  • SKILL.md3.4 KB
  • eval-output.json3.8 KB
  • eval-trigger.json5 KB
  • moon.yml86 B
  • references/arenas-and-pools.md2.8 KB
  • references/caller-owns-memory.md1.9 KB
  • references/ownership-and-lifetimes.md2.3 KB
  • references/virtual-memory.md3.9 KB
  • sources.json4.7 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.