World Congress 2024 Aug 20, 2024 Session details

An (In-)Complete Guide to C++ Object Lifetimes

Jonathan Müller

Are hidden dangling references silently crashing your C++ codebase? Demystify the complex rules of object lifetimes, temporary extensions, and memory reuse to banish undefined behavior.

Pause
Mute Enter Fullscreen
#1 about 2 min

Core definitions of C++ objects and data references

Objects are fundamental building blocks with type, storage, and value, while functions and references are not objects.

#2 about 2 min

The five lifecycle steps of a compiled C++ object

An object is bound to an abstract machine property dictating when it can be safely manipulated between storage allocation and deallocation.

#3 about 3 min

Variable definitions and storage duration syntax rules

Storage duration dictates the minimum potential lifetime of an object's memory across automatic, static, or thread-local contexts.

#4 about 2 min

Handling optional initialization and indeterminate memory values

Omitting initialization results in indeterminate values that trigger either undefined or erroneous behavior upon access.

#5 about 1 min

Manual object lifecycle logic with new and delete expressions

Heap allocation constructs provide manual control over the entire lifecycle logic of dynamic class instances.

#6 about 2 min

Creation and lifecycle timelines of temporary C++ objects

Temporary objects are implicitly created to hold pure values and are typically destroyed securely at the end of the full expression.

#7 about 3 min

Risks of temporary lifetime extensions via implicit references

Binding a temporary directly to a reference extends its lifetime, but indirect bindings through function operators often result in dangling references.

#8 about 2 min

Extended temporary memory lifetimes inside range-based for loops

Modern language rules extend the lifetime of all temporaries created specifically in the range expression of a for loop.

#9 about 2 min

Explicit object construction using the placement new syntax

Placement new allows for the direct invocation of an object's constructor in a specifically pre-allocated memory location.

#10 about 2 min

Acquiring and safely reusing physical memory for placement new

Raw storage can be provisioned through allocation functions or uninitialized arrays to decouple memory management from object creation.

#11 about 4 min

Transparent and non-transparent object memory runtime replacement rules

Replacing objects in reused storage maintains valid pointers only if the replacement is completely transparent regarding underlying types and mutability.

#12 about 2 min

Re-verifying non-transparent memory pointers with standard launder functions

A specialized identity function explicitly instructs the compiler to retrieve updated values from memory after a non-transparent replacement occurs.

#13 about 4 min

Implicit object creation triggers to resolve undefined behavior calls

Operations like memory allocation and byte copying can retroactively instantiate trivial objects to fulfill abstract machine access prerequisites.

#14 about 2 min

Initializing raw network buffers via explicit object lifetime starts

Developers can prevent undefined behavior when mapping structures onto raw byte arrays by manually forcing the lifetime commencement.

#15 about 2 min

Implicit destruction process dynamics and related memory leak concerns

Creating a new object in occupied memory organically concludes the existing object's lifetime without safely invoking its destructor.

Matching moments

5:20 min

Managing memory and resources with deterministic object destruction

Andreas Fertig · WWC 2021

1:17 min

Wrapping up common golang memory retention practices

Manfred Bjørlin Manfred Bjørlin · WWC Europe 2026

1:17 min

Transitioning from C to Java for object-oriented development

Silvio Barbieri · Coffee With Developers

5:07 min

Addressing garbage collection performance impacts and scope pitfalls

Eli Holderness · LIVE

8:29 min

Discussion on JIT memory parameters and cross-language benchmarking

Daniel Strmečki · LIVE

1:39 min

Analyzing object allocation with new instance tracking

Shai Almog · WWC 2022

Upcoming sessions on this topic

Open session

World Congress 2026 North America

When Humans Stop Writing Code: Rethinking Languages, Compilers, and Responsibility

Simon Auer

Organizer of flutter vienna meetup and CEO of marqably

Simon Auer
Open session

World Congress 2026 North America

Offloading IoT State: Solving the Memory Crisis on Legacy Hardware

Pravin Nagare

Senior Software Engineer, Roku

Pravin Nagare
Open session

World Congress 2026 North America

Understanding LLM Architectures: Inside the Design of Modern Models

Jofia Jose Prakash

Enterprise AI Architect at American Chemical Society

Jofia Jose Prakash
Open session

World Congress 2026 North America

You Can’t Re-Run Sunlight: Designing ML Data Architectures for Physical AI

An Phan

Senior Data Infrastructure Engineer @ Hippo Harvest

An Phan
Open session

World Congress 2026 North America

public void saveMoney(AI): The Developer's Guide to Unit Economics

Hrushikesh Pokala

Senior Software Engineer Lead at Equifax

Hrushikesh Pokala
Open session

World Congress 2026 North America

Building World-Aware Robots with Agent Memory and Context Graphs

Zaid Zaim

Developer Advocate EMEA at Neo4j | Microsoft AI MVP

Zaid Zaim