Tag: RAII
14 posts
-
C++ Memory Leaks: Causes, Detection, and Prevention
Understand heap leaks: lost pointers, exception paths, shared_ptr cycles. Valgrind, ASan/LSan, heap profilers, Visual Studio, RAII, suppression files, and CI.
-
C++ RAII Explained | Why Constructors and Destructors Prevent Leaks
A deep dive into C++ RAII grounded in a real production connection-leak incident, covering exception safety, the C++ Core Guidelines, and composable ownership.
-
shared_ptr and weak_ptr Internals: Control Blocks, Cycles, enable_shared_from_this and Aliasing
std::shared_ptr reference counting, control blocks, weak_ptr observers, cycles, enable_shared_from_this, aliasing, custom deleters, and production patterns in modern C++.
-
std::unique_ptr: Exclusive Ownership, make_unique, Custom Deleters and Moving Ownership
std::unique_ptr explained: RAII, make_unique, custom deleters, arrays, move semantics, PIMPL, containers, and exception-safe factories.
-
C++ [[nodiscard]] Guide: Ignore Return Values Safely
Turn ignored return values into compiler warnings with [[nodiscard]]: error codes, RAII guards, factories, C++20 reason strings, and missing-warning cases.
-
C++ Exception Safety — Basic, Strong, and Nothrow Guarantees
C++ exception safety: basic, strong, and nothrow guarantees, RAII, copy-and-swap, destructor rules, and common pitfalls—with concise examples.
-
C++ malloc vs new vs make_unique
C++ malloc vs new vs make_unique compared: constructor calls, type safety, failure behavior (nullptr vs bad_alloc), alignment, operator new overloading, and why make_unique is the default in modern C++.
-
C++ Custom Deleters for unique_ptr and shared_ptr: Function Pointers, Lambdas, and Functors
When custom deleters are needed, comparing function pointers·lambdas·function objects, differences in type·storage between unique_ptr and shared_ptr.
-
What new and delete Actually Do in C++: operator new, delete[] Mismatch, Alignment, Placement new and Arenas
How a C++ new expression splits into operator new plus a constructor, why delete vs delete[] corrupts the heap, aligned and placement new, and pmr arenas.
-
C++20 std::jthread: Auto-Join, Cooperative Cancellation with stop_token, and Its Limits
C++20 std::jthread explained: why std::thread terminates without join, how jthread requests stop and joins in its destructor, how stop_token, stop_callback, and condition_variable_any make waits cancellable, and the cases where auto-join still hangs.
-
C++ Object Lifetime: Storage Duration, RAII, and Dangling
C++ lifetime and storage duration: automatic, static, dynamic, thread_local; destruction order; temporaries; smart pointers and RAII.
-
C++ Exceptions Done Right: Catch by Reference, Safety Guarantees, RAII and noexcept
Handle C++ exceptions safely: catch by const reference, basic/strong/nothrow guarantees, RAII cleanup, noexcept on moves, and when to use std::expected.
-
Finding C++ Memory Leaks: Valgrind and AddressSanitizer
Find C++ heap leaks with Valgrind, ASan/LeakSanitizer and the Visual Studio CRT debug heap, then fix early returns, exception paths and shared_ptr cycles.
-
C++ Copy & Move Constructors: Rule of Five and RAII
Rule of Five in C++: copy/move constructors and assignment, deep copy vs shallow, self-assignment, noexcept moves, copy elision, and FileHandle patterns.