13eholder/modern-cpp-skills/m02-resource

Claude Code and agent skill by 13eholder/modern-cpp-skills

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Mastering C++ Smart Pointers: unique_ptr, shared_ptr, weak_ptr. Triggers: memory management, cycles, enable_shared_from_this, make_unique, make_shared, custom deleters.

Install

npx vskill@latest install 13eholder/modern-cpp-skills/m02-resource

SKILL.md

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

IssueDesign Question
Memory Leak (Cycles)Do you have shared_ptr pointing to each other? Cycle = Leak.
Dangling PointerDid you store a weak_ptr or raw pointer but check it too late?
Double FreeDid you make two unique_ptrs from one raw pointer?
PerformanceAre you copying shared_ptr unnecessarily? (Atomic ops).

Thinking Prompt

  1. 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).
  1. Is this a Cycle?
  • Parent -> Child (shared_ptr).
  • Child -> Parent (weak_ptr).
  • If Child holds shared_ptr to Parent, they never die.
  1. Do I need a custom deleter?
  • Managing C-APIs (FILE*, SDL_Surface*)?
  • unique_ptr<FILE, DeclType(&fclose)> handles this perfectly.

Trace Up / Down

  • Trace Up:
  • Issue: "Application memory usage grows endlessly but no 'leaks' reported by Valgrind."
  • Cause: shared_ptr cycle. 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

PatternCostUse When
`make_unique`ZeroCreating new heap objects.
`make_shared`1 AllocCreating access-controlled shared objects.
`weak_ptr`Control BlockBreaking cycles, Caching.
`enable_shared_from_this`ZeroNeed shared_from_this() inside member function.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
12
Repository forks
1
7-day trend score
13

Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 23 Mar 2026, 8 months ago.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/13eholder/modern-cpp-skills/m02-resource/badge)](https://verified-skill.com/skills/13eholder/modern-cpp-skills/m02-resource)

Something wrong with this skill or its page? Tell us.