[ TOPIC ]
memory-management
42 real merged PRs across 13 projects, ordered easiest to hardest. Read them in order to see how memory-management shows up in production code, then go deeper with the free papers and talks below.
[ 01 // REAL PRs ]
Next (mid) · 29
fix: accumulate RetrieveResultCache size instead of recomputing it per merge
This PR teaches how to turn a quadratic-time accumulation pattern into a linear one by incrementally tracking the size of a merged protobuf message, with careful attention to what data is retained and how to conservatively estimate memory usage.
sqlite: re-validate database state after reading options
This PR teaches how to defensively re-check resource state after user-supplied code runs, preventing use-after-close bugs and subtle security/memory issues in native bindings.
scrape: support zstd-compressed responses
This PR teaches how to safely add support for a new compression format (zstd) to a networked service, including decoder pooling, memory safety, feature flag gating, and robust error handling.
fix(runtime-vapor): clean up teleport targets on scope disposal
This PR demonstrates how to ensure proper cleanup of dynamically created DOM elements (teleports) in a reactive UI framework, with robust regression testing for edge cases.
fix(core): share existing singleton providers with lazily loaded modules
This PR teaches how to correctly share singleton providers between eagerly and lazily loaded modules, preventing resource leaks and duplicate instantiation in a dependency injection container.
ffi: reject detached ArrayBuffers as pointers
This PR teaches how to robustly validate and reject detached ArrayBuffers in FFI pointer conversions, ensuring safe memory handling and thorough error testing across JS and C++ boundaries.
[FIXED] Dynamic max_file_store shrinks on restart as the store grows
This PR demonstrates how to correctly handle dynamic resource limits (disk usage) across restarts, ensuring stability and correctness by accounting for already-used resources and providing a robust test for regression.
lightning: fix corrupted DECIMAL values in dictionary-encoded parquet files (#70436)
This PR teaches how in-place mutation of shared buffers can corrupt data when decoding dictionary-encoded values, and how to safely isolate buffers to prevent subtle memory bugs, with a strong regression test.
crossks: clean up virtual server info on close and bootstrap failure
This PR teaches how to robustly clean up distributed system resources (etcd leases and records) on both normal shutdown and partial failure, with deterministic regression tests to verify cleanup.
dumpformat: fix corrupted DECIMAL values in dictionary-encoded parquet files
This PR teaches how shared buffer ownership in dictionary-encoded data can cause subtle data corruption, and how to fix it by copying data before in-place mutation.
Avoid deep copy of AccessRights in getGrantQueriesImpl when it is only read
This PR teaches how to optimize performance by avoiding unnecessary deep copies of complex data structures, with careful attention to when mutation is required and how to validate the change with targeted regression tests.
JSON Deep Merge Fix
This PR teaches how to refactor a recursive algorithm into an iterative one to prevent stack overflows on deeply nested data, while also introducing robust error handling for recursion depth and improving test coverage.
buffer: pad aligned allocations by a multiple of 8
This PR teaches how careful memory alignment and buffer padding can prevent subtle bugs with typed array views and ensure correct low-level memory handling in JavaScript runtimes.
sea: keep ELF segments on separate pages in --build-sea output
This PR teaches how low-level memory layout issues in ELF binaries can cause runtime failures on specific kernels, and how to write targeted tests to prevent such regressions.
events: fix weak listener retention overwrite
This PR teaches how to fix subtle memory retention bugs involving weak references and event listeners, with a clear explanation and regression tests.
enhance: reduce Tantivy index build write amplification [3.0]
This PR teaches how to reduce write amplification in index building by tuning memory budgets and merge policies for in-memory and sealed index writers.
enhance: reduce Tantivy index build write amplification
This PR teaches how to reduce write amplification in text index builds by carefully managing memory budgets and merge policies for in-memory and sealed index segments.
enhance: reduce Tantivy index build write amplification [2.6]
This PR teaches how to reduce write amplification in index building by tuning memory budgets and merge policies for different index build modes.
server: limit the size for COM_STMT_SEND_LONG_DATA in each connection (release-7.5-20260724-v7.5.7) (#70350) | tidb-test=release-7.5.7 tikv=v7.5.7 pd=v7.5.7 tiflash=v7.5.7
This PR teaches how to enforce per-connection memory limits for prepared statement long-data in a database server, including careful memory accounting, error signaling, and robust test coverage for quota enforcement and cleanup.
fix:[3.0] prevent crash on zero-length Arrow C Data buffers
This PR teaches how to safely handle zero-length C data buffers in Go to prevent unsafe pointer issues and runtime crashes, including how to write a targeted regression test for such a bug.
[release/11.0] [System.Management] Make generated WMI wrappers disposable
This PR teaches how to safely expose resource cleanup in generated types by implementing IDisposable, and highlights the API and compatibility considerations of such a change.
server: limit accumulated COM_STMT_SEND_LONG_DATA size (release-7.5-20260724-v7.5.7) (#69694) | tidb-test=release-7.5.7 tikv=v7.5.7 pd=v7.5.7 tiflash=v7.5.7
This PR demonstrates how to enforce resource limits (max packet size) for prepared statement parameters, propagate errors at the correct protocol stage, and write targeted tests for boundary and error conditions.
[Perf Tracks]: Clear potentially large measures
This PR teaches how to prevent memory leaks in performance measurement code by explicitly clearing browser performance measures after use.
[WebAssembly] Fix __init_tls_base global in coop threading
This PR teaches how to correctly initialize and manage thread-local storage (TLS) base globals in WebAssembly modules, especially handling differences between PIC and non-PIC modes for cooperative threading.
[mlir][Printer] Honor --mlir-elide-resource-strings-if-larger when serializing of large blobs
This PR teaches how to avoid unnecessary memory and CPU usage by precomputing output size and short-circuiting expensive serialization when a size limit is exceeded.
[flang][OpenMP] incorrect handling for local variable in OpenMP parallel workshare firstprivate(P)
This PR teaches how to correctly handle thread-local storage and initialization for OpenMP 'firstprivate' pointer variables in parallel workshare constructs, avoiding subtle concurrency bugs.
[mlir][bufferization] Fix crash when returning an allocation twice
This PR teaches how to safely handle multiple returns of the same allocation by deferring erasure, reusing buffers, and adding copies, with thorough testing for static and dynamic cases.
[clang] Don't add documentation comments to the AST if not requested
This PR teaches how to conditionally retain documentation comments in the AST only when needed, reducing memory usage and improving performance by refactoring comment handling logic.
src: disable V8 external memory reasonable size check
This PR teaches how to override and disable a VM's memory safety check to better fit a host application's needs, while respecting user-supplied configuration and ensuring graceful error handling.
Go deep (senior) · 13
fix(runtime-vapor): dispose component v-for item resources on removal
This PR teaches how to prevent memory/resource leaks in reactive UI frameworks by correctly scoping and disposing per-item resources in dynamic component lists, with robust regression tests and careful teardown ordering.
[mono][wasm][AOT] Pin `OP_MOVE` destinations in the GC pin area
This PR teaches how precise GC root tracking is implemented and debugged in a cross-platform AOT compiler, especially for WebAssembly's unique execution model.
Check for SIG_IGN and SIG_DFL before calling previous signal handler
This PR teaches how to robustly handle inherited signal handler state across execve on macOS, including defensive checks against stale pointers and how to write a regression test for subtle OS-level signal handling bugs.
Fix generic virtual dispatch hang after multiple AssemblyLoadContext unloads
This PR teaches how subtle bugs in cache sentinel handling can cause memory leaks or stale data after unloading assemblies, and demonstrates robust regression testing and defensive coding in complex runtime systems.
Run the deadly signal handlers on the alternative stack
This PR teaches how to robustly handle fatal signals (like stack overflows) by ensuring signal handlers run on an alternative stack, preventing silent failures and enabling stack trace reporting even when the main stack is exhausted.
[LICM] Ignore AA tags on conditional stores in scalar promotion.
This PR teaches how compiler optimizations must carefully handle alias analysis metadata when promoting stores out of loops, especially regarding conditional execution and speculative stores.
[DOM] Unobserve fragment IntersectionObserver targets after exit
This PR teaches how to manage IntersectionObserver lifecycle in React fragments to avoid memory leaks by delaying unobserve calls until after paint, with cancellation logic for reinsertion, demonstrated with detailed tests and careful resource cleanup.
Reduce next-solver memory usage by interning CanonicalQueryInput
This PR demonstrates how interning a frequently-duplicated data structure can drastically reduce memory usage in a complex system, with practical tradeoffs and implementation details in a real compiler codebase.
tls: read the peer certificate chain without consuming it
This PR teaches how to fix a subtle bug involving destructive reads of TLS peer certificate chains by duplicating certificates to preserve the chain, adding a new presence check API, and includes a thorough test to ensure non-destructive repeated reads.
sqlite: keep sessions alive across SQLite callbacks
This PR teaches how to manage object lifetimes and prevent use-after-free bugs by pinning weakly referenced objects during callbacks that can trigger garbage collection in a native addon environment.
quic: release stream arenas before cleanup
This PR teaches how to safely manage memory and resource cleanup in the presence of asynchronous destruction and JavaScript/native interop, including regression testing for subtle teardown bugs.
atomic volatile: add intrinsics
This PR teaches how to extend low-level atomic intrinsics with a volatile flag across a compiler and standard library, highlighting the challenges of API evolution, cross-backend support, and the propagation of new semantics through a complex system.
[LoopVectorize] Clear stale CycleAnalysis after vectorizing a loop
This PR teaches how to prevent use-after-free bugs in compiler passes by explicitly invalidating cached analyses that may hold stale pointers after IR mutation.
[ 02 // MUST-READ PAPERS ]
Free to read, ranked by citations.
- Mesh: compacting memory management for C/C++ applicationsBobby Powers, David Tench, Emery D. Berger · ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI) · 201924 citationsfree PDF
- Hoard: A Scalable Memory Allocator for Multithreaded ApplicationsEmery Berger et al. · ASPLOS · 2000free PDF
[ 03 // FREE VIDEOS & TALKS ]
Ranked by views.
other topics

