Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the intrusive_ptr and replace it with std::shared_ptr. #740

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

copybara-service[bot]
Copy link

Remove the intrusive_ptr and replace it with std::shared_ptr.

Prior to this change, we manage the cleanup of some resources where many structures may point to them and it is unclear the order in which they may go out of scope with a new intrusive_ptr, a refcounted pointer that we rolled ourselves. This change moves us to instead use the standard C++ std::shared_ptr.

std::shared_ptr is less preferred in the style guide to std::unique_ptr. However, this is because of the shared ownership responsibility, and the style guide prefers each object to have one owner when possible. In the case that an object truly must have shared ownership, std::shared_ptr is recommended.

This change significantly reduces the amount of custom code we have to maintain. Not only that, the eliminated code manages a relatively tricky lifetime/owernship aspect.

Prior to this change, we manage the cleanup of some resources where many structures may point to them and it is unclear the order in which they may go out of scope with a new `intrusive_ptr`, a refcounted pointer that we rolled ourselves. This change moves us to instead use the standard C++ `std::shared_ptr`.

`std::shared_ptr` is [less preferred](https://google.github.io/styleguide/cppguide.html#Ownership_and_Smart_Pointers) in the style guide to `std::unique_ptr`. However, this is because of the shared ownership responsibility, and the style guide prefers each object to have one owner when possible. In the case that an object truly must have shared ownership, `std::shared_ptr` is recommended.

This change significantly reduces the amount of custom code we have to maintain. Not only that, the eliminated code manages a relatively tricky lifetime/owernship aspect.

PiperOrigin-RevId: 476985992
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants