You’re joining a fintech risk engine written in modern C++ that processes millions of transactions per day under strict latency SLOs and regulatory audit requirements. A single memory bug (leak, double-free, use-after-free) can cause process crashes, corrupted risk decisions, or hard-to-reproduce incidents that block releases.
Explain your experience with C++ memory management by walking through how you would design, implement, and debug memory ownership in a performance-sensitive service.
Address the following:
std::unique_ptr, std::shared_ptr, and std::weak_ptr. When is shared_ptr a code smell? How do you avoid cycles?Assume the interviewer expects implementation-level depth: object layout and allocation, move/copy semantics, destructor behavior, container ownership patterns, and trade-offs between safety and performance. Use a concrete example (e.g., a graph of risk rules, an in-memory cache, or a request pipeline) to demonstrate how you’d apply these principles.