Dynamic Memory

Allocate memory at runtime with new and delete. Understand stack vs heap and avoid memory leaks.

50 lessons
197 min

Lessons

1. Intro

Memory control

4m

2. Stack vs Heap

Memory layout

4m

3. Stack Memory

Local variables

4m

4. Heap Memory

Long-lived data

4m

5. The new Operator

Heap allocation

4m

6. Quiz: Memory Basics

Memory allocation

2m1 problems

7. The delete Operator

Manual cleanup

4m

8. new and delete for Arrays

Heap array allocation

4m

9. Quiz: Memory cleanup

Memory cleanup

3m1 problems

10. Quiz: new and delete

Knowledge check

3m1 problems

11. Memory Leaks

Forgetting delete

4m

12. Dangling Pointers

Deleted memory access

4m

13. Double Delete

Repeated free

4m

14. nullptr After delete

Defensive programming

4m

15. When to Use Dynamic Memory

Allocation decisions

4m

16. Quiz: Memory cleanup

Memory cleanup

3m1 problems

17. Dynamic Arrays

Variable-sized allocation

4m

18. Resizing Dynamic Arrays Manually

Grow and shrink

4m

19. Quiz: Memory Leaks

Knowledge check

3m1 problems

20. Problems with Raw Pointers

Manual management risks

4m1 problems

21. Introduction to Smart Pointers

Automatic cleanup

4m

22. What is unique_ptr?

Single owner

4m

23. Creating unique_ptr

Factory function

4m

24. unique_ptr Automatic Cleanup

Scope-based delete

4m

25. Quiz: Knowledge check

Knowledge check

3m1 problems

26. Moving unique_ptr

Ownership transfer

4m

27. Quiz: unique_ptr

Knowledge check

3m1 problems

28. What is shared_ptr?

Multiple owners

4m

29. Creating shared_ptr

Factory function

4m

30. Reference Counting

Ownership tracking

4m

31. When shared_ptr Deletes

Last owner cleanup

4m

32. Quiz: Variable alias

Variable alias

3m1 problems

33. weak_ptr Basics

Non-owning reference

4m

34. Quiz: shared_ptr

Knowledge check

3m1 problems

35. Choosing the Right Smart Pointer

Ownership patterns

4m

36. Smart Pointers vs Raw Pointers

Modern C++ practice

4m

37. Practice Problems

Apply what you learned

4m7 problems

38. Quiz: Smart Pointer Choice

Knowledge check

3m1 problems

39. Problem - Flexible Array

Heap memory basics

4m1 problems

40. Flexible Array - The Idea

Memory location matters

5m

41. Flexible Array - Algorithm

Implementation approach

4m

42. Flexible Array - Implementation

Pseudocode solution

7m1 problems

43. Lessons from Flexible Array

summary

4m

44. Problem - Node Creation

Heap-based data structures

4m1 problems

45. Node Creation - The Idea

Building chains

5m

46. Node Creation - Algorithm

Implementation approach

4m

47. Quiz: Knowledge check

Knowledge check

3m1 problems

48. Node Creation - Implementation

Pseudocode solution

7m1 problems

49. Lessons from Node Creation

summary

4m

50. Section Recap

What we learned

5m

Ready to start learning?

Access all 50 lessons with interactive content and progress tracking.