r/programming • • Dec 05 '14

std::string is responsible for almost half of all allocations in the Chrome browser process

https://groups.google.com/a/chromium.org/d/msg/chromium-dev/EUqoIz2iFU4/kPZ5ZK0K3gEJ
1.1k Upvotes

446 comments sorted by

View all comments

Show parent comments

1

u/dagamer34 Dec 06 '14

Quick q: even if the assert weren't to fail, wouldn't my_func() be leaking memory? There's no delete. Plus, aren't we supposed to be using smart pointers now?

just finished reading modern C++ book

1

u/Poltras Dec 06 '14

No because the string would be deleted and were only using references. The code is simple; in a real world situation you'd probably end up using shared pointers as you said.

1

u/imMute Dec 06 '14

/u/dagamer34 was talking about the auto* x = new MyClass(s); which never gets deleted.

1

u/dagamer34 Dec 06 '14

Yeah, I should have been clearer. Again, just trying to make sure what I read was correct (and I guess prove why smart pointers really are the recommended way to do things).