memory-safety-patterns
Memory-safe programming patterns for RAII, ownership, smart pointers, and resource management across Rust, C++, and C.
- Covers six core memory bug categories (use-after-free, double-free, leaks, buffer overflow, dangling pointers, data races) with language-specific prevention strategies
- Provides RAII patterns in C++ with destructors, lock guards, and transactions; smart pointer guidance (unique_ptr, shared_ptr, weak_ptr) with custom deleters
- Implements Rust ownership, borrowing, lifetimes, and interior mutability (Cell, RefCell, Rc, Arc) with compile-time safety guarantees
- Includes safe C patterns using goto cleanup, opaque pointers with create/destroy pairs, and GCC cleanup attributes
- Demonstrates bounds checking via containers and spans in C++, and iterators in Rust; thread-safe patterns using atomics, mutexes, and RwLock across languages
Memory Safety Patterns
Cross-language patterns for memory-safe programming including RAII, ownership, smart pointers, and resource management.
When to Use This Skill
- Writing memory-safe systems code
- Managing resources (files, sockets, memory)
- Preventing use-after-free and leaks
- Implementing RAII patterns
- Choosing between languages for safety
- Debugging memory issues
Core Concepts
1. Memory Bug Categories
| Bug Type | Description | Prevention |
|---|
More from wshobson/agents
tailwind-design-system
Build scalable design systems with Tailwind CSS v4, design tokens, component libraries, and responsive patterns. Use when creating component libraries, implementing design systems, or standardizing UI patterns.
41.0Ktypescript-advanced-types
Master TypeScript's advanced type system including generics, conditional types, mapped types, template literals, and utility types for building type-safe applications. Use when implementing complex type logic, creating reusable type utilities, or ensuring compile-time type safety in TypeScript projects.
40.5Knodejs-backend-patterns
Build production-ready Node.js backend services with Express/Fastify, implementing middleware patterns, error handling, authentication, database integration, and API design best practices. Use when creating Node.js servers, REST APIs, GraphQL backends, or microservices architectures.
31.8Kpython-performance-optimization
Profile and optimize Python code using cProfile, memory profilers, and performance best practices. Use when debugging slow Python code, optimizing bottlenecks, or improving application performance.
22.1Kapi-design-principles
Master REST and GraphQL API design principles to build intuitive, scalable, and maintainable APIs that delight developers. Use when designing new APIs, reviewing API specifications, or establishing API design standards.
20.3Kpython-testing-patterns
Implement comprehensive testing strategies with pytest, fixtures, mocking, and test-driven development. Use when writing Python tests, setting up test suites, or implementing testing best practices.
19.7K