CS 70

Group 5: Object Lifetime

  • LHS Cow speaking

    This group of topics relate to understanding how the phases of object lifetime apply to custom classes, including classes that allocate their own memory on the heap.

  • RHS Cow speaking

    Knowing when data members are initialized, when different member functions are called, and when the compiler will synthesize functions for you is the source of a lot of bugs in complex C++ programs. Being able to reason about object lifetime now will help avoid lots of trouble later!

Topics

You will know that you have achieved this group of learning objectives when you are able to

  • Goal 5A: Model Objects:
    • Draw memory models for classes that allocate memory on the heap
  • Goal 5B: Lifetime Timing:
    • Identify where in a program each phase of lifetime (allocation, initialization, use, destruction, deallocation) happens for an instance of a class.
  • Goal 5C: Pointers to Classes:
    • Explain how references and pointers to instances of classes behave in terms of object lifetime
  • Goal 5D: Constructors and Destructors:
    • Write constructors, destructors, and assignment operators, including for classes that allocate memory on the heap.
    • Use the keywords default and delete to control if and how those functions will be synthesized by the compiler.

Need More Practice?

This group of goals are addressed in the following places:

(When logged in, completion status appears here.)