m02-resource
Skill14 starsChanged 9 months agoMITView on GitHub
Mastering C++ Smart Pointers: unique_ptr, shared_ptr, weak_ptr. Triggers: memory management, cycles, enable_shared_from_this, make_unique, make_shared, custom deleters.
7 other projects use a version of this.
Adopted by
Most recently taken up by
- TeddyAlbina/skillstheir own version, first seen Nov 1, 2026
- moeru-ai/auvtheir own version, first seen Oct 10, 2026
- fjrevoredo/mini-diariumtheir own version, first seen Oct 8, 2026
- ZhangHanDong/rust-skillstheir own version, first seen Oct 8, 2026
- MovGP0/Skillstheir own version, first seen Jun 30, 2026
- pocket-veto/pocket-vetotheir own version, first seen Jun 27, 2026
Other versions7 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 7
- ZhangHanDong/rust-skills★ 1.5ksame name
- actionbook/rust-skills★ 1.5ksame name
- fjrevoredo/mini-diarium★ 318same name
- moeru-ai/auv★ 207same name
- TeddyAlbina/skills★ 2same name
- MovGP0/Skills★ 1same name
- pocket-veto/pocket-veto★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository14 other files it gives its agents.
- cpp20-skill-creatorSkill
- m01-ownershipSkill
- m03-mutabilitySkill
- m04-zero-costSkill
- m05-type-drivenSkill
- m06-error-handlingSkill
- m07-concurrencySkill
- m09-domainSkill
- m10-performanceSkill
- m11-ecosystemSkill
- m12-lifecycleSkill
- m13-domain-errorSkill
- m14-mental-modelSkill
- m15-anti-patternSkill
The file
We split this skill into the rules it gives an agent
2 rules. 0 are common, 1 is distinctive, and 1 is very specific to this project.
0
Common
Most of the 7 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 28
Always start here. It has zero overhead (size = raw pointer).
- Very specific: line 34
If Child holds shared_ptr to Parent, they never die.
“Common” is measured: kept by at least 6 in 10 of the 7 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
C++ Smart Pointers (Resource Management)
Core Question
How many owners does this resource to have?
- One:
std::unique_ptr(90% of cases). - Many:
std::shared_ptr. - Observer:
std::weak_ptr.
Error → Design Question
| Issue | Design Question |
| Memory Leak (Cycles) | Do you have shared_ptr pointing to each other? Cycle = Leak. |
| Dangling Pointer | Did you store a weak_ptr or raw pointer but check it too late? |
| Double Free | Did you make two unique_ptrs from one raw pointer? |
| Performance | Are you copying shared_ptr unnecessarily? (Atomic ops). |
Thinking Prompt
- Can I use
unique_ptr?- Always start here. It has zero overhead (size = raw pointer).
- It forces you to think about ownership transfer (
std::move).
- Is this a Cycle?
- Parent -> Child (
shared_ptr). - Child -> Parent (
weak_ptr). - If Child holds
shared_ptrto Parent, they never die.
- Parent -> Child (
- Do I need a custom deleter?
- Managing C-APIs (
FILE*,SDL_Surface*)? unique_ptr<FILE, DeclType(&fclose)>handles this perfectly.
- Managing C-APIs (
Trace Up / Down
- Trace Up:
- Issue: "Application memory usage grows endlessly but no 'leaks' reported by Valgrind."
- Cause:
shared_ptrcycle. The reachable memory is technically "owned", just mutually. - Fix: Break the cycle with
weak_ptr.
- Trace Down:
- Intent: "I need a list of heterogeneous objects."
- Code:
std::vector<std::unique_ptr<Base>>
Quick Reference
| Pattern | Cost | Use When |
make_unique | Zero | Creating new heap objects. |
make_shared | 1 Alloc | Creating access-controlled shared objects. |
weak_ptr | Control Block | Breaking cycles, Caching. |
enable_shared_from_this | Zero | Need shared_from_this() inside member function. |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

