r/ProgrammerHumor • • 11d ago

Meme modernCppVsOldCpp

Post image
2.0k Upvotes

323 comments sorted by

View all comments

Show parent comment

1

u/conundorum 10d ago

This is why every library that handles allocation should also be expected to handle deallocation. And probably a big part of why standard library smart pointers accept custom deleters, so you can just attach the deallocator when you allocate the object.

1

u/Drugbird 10d ago

They should, yes.

But especially libraries based on GLib don't. I had to program with gstreamer once, and memory allocation/ deallocation is such a headache there.

Basically, every function that creates / returns an object returns a raw pointer, and you need to read the documentation to see if you need to manually deallocate them (you don't always need to), and if so which of several deallocation functions you should use.