Live and Let Die -- Martin Janzen
Resource lifetime management can be problematic. Martin Janzen reminds us how important destructors are and when to be mindful of their limitations.
Live and Let Die
By Martin Janzen
From the article:
Most experienced C++ programmers will agree that one of the best properties of our language is the ability to manage object lifecycles using constructors and destructors.
Bjarne Stroustrup [Stroustrup19] has described
ctor/dtorpairs as one of C++’s most elegant features, giving us the ability to create clean types which tidy up after themselves, with predictable performance, minimal overhead, and no need for garbage collection.In this year’s ACCU Conference Lightning Talks, Nico Josuttis singled out destructors as (spoiler alert!) “the most important C++ feature” [Josuttis23]; and Wiktor Klonowski told a sad tale of time wasted debugging a .NET program that kept running out of ports, a fate which could have been avoided by the use of
dtors [Klonowski23].At the same conference, as well as at the recent C++ On Sea, numerous speakers talked about C++ and safety, a subject that’s been very much in the news recently [NSA22], with C++ predictably receiving a lot of flak for the ease with which one can write code containing buffer overflows, memory leaks, and of course a rich and varied choice of ways to introduce undefined behaviour (UB).
In its favour, though, C++ also provides at least one way in which we can improve safety, and reliability, greatly, by use of the powerful RAII (Resource Acquisition is Initialisation) idiom: taking ownership of a resource in the ctor, then releasing it in the
dtor.

A new episode of the series about SObjectizer and message passing:
In this blog post, we’ll look at several different view/reference types introduced in Modern C++. The first one is
The Visual C++ team attended CppCon 2023, the largest in-person C++ conference, in Aurora, Colorado from October 2-6th. There were over 700 attendees from the C++ community, and we really enjoyed getting a chance to meet all of you and talk about your unique backgrounds and C++ experiences.
A new episode of the series about SObjectizer and message passing:
In this post we talk about how data structure data layout effects software performance and how, by modifying it, we can speed up the access and modification of the data structure.
A report out from this week's ISO C++ standards committee meeting, which just ended:
Learn how the overload pattern works for
A new episode of the series about SObjectizer and message passing:
The time has come, fellow devs. We are on our way to uncover the newest concept of C++ language – Coroutines.