← udacity portfolio
cpp nd · systems cpp · April 2020

Memory-Management Chatbot

Refactor a leaky C++ chatbot to demonstrate every smart-pointer + ownership pattern in the language. The capstone of the C++ memory module.

What it did

The C++ nanodegree’s “Memory Management” module ends with a chatbot project that’s intentionally full of raw pointers, manual new/ delete, and ownership ambiguity. The work is to refactor it so every allocation matches a single smart-pointer pattern, with zero leaks.

Specifically the task is to apply each of the 5 ownership models:

RuleExample in the chatbot
Exclusive ownership (unique_ptr)Each GraphNode owns its ChatBot instance
Shared ownership (shared_ptr)A ChatLogic shared across the GUI + the graph
Weak observation (weak_ptr)Edges back-referencing nodes (avoids cycles)
Move-only resourcesThe chatbot image (large) moves into nodes, not copies
Rule of FiveChatBot itself implements full copy/move ctor + assignment

What was actually tricky

What I’d do differently with hindsight

What it taught me

C++ memory ownership is a graph problem, not a syntax problem. The question is never “where do I put new?” — it’s “what’s the ownership tree, and where are the cycles?” Once that’s clear, the smart-pointer choices are mechanical. Most C++ bugs in my code since this project have been ownership-graph bugs, not pointer- arithmetic bugs.


Source archive: Shivam-Bhardwaj/Memory-Management-Chatbot (archived)
Writeup last touched: 2026-05-22