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

refactor(NLVObject): use smart pointers for tracking object lifetime #76

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

Conversation

Rush
Copy link
Contributor

@Rush Rush commented Aug 27, 2016

@mbroadst I had a lazy evening and a crazy idea to use weak pointers instead of NLVObjectPtr. Note: enable_shared_from_this is probably not necessary but I wanted you to see this branch earlier rather than later to get some comments.


void ClearChildren() {
for (auto& ptr: children_) {
if (auto object = ptr.lock()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbroadst this is the reward, ability to see if those weak pointers are stil valid.

@mbroadst
Copy link
Contributor

yeah definitely now that we've committed to c++11, smart pointers are of course the way to go :)

HandleType handle_;
NLVObjectBasePtr* parentReference_;

std::unique_ptr<HandleValue, decltype(&CleanupHandler::cleanup)> handle_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@mbroadst
Copy link
Contributor

@Rush I left a few comments. I really like the direction this is taking, but I wonder if we can't split the single commit into at least two:

  • one for the move to std::unique_ptr + all of the handle_ => handle() changes
  • one for your idea with std::shared_ptr

It's a bit hard to review this mono-commit version because of all the handle_ => handle() noise, and frankly I would merge that one right in because it's pretty straightforward and obviously the better solution.

Thoughts?

@Rush
Copy link
Contributor Author

Rush commented Aug 27, 2016

Sure, I'll split it later this evening probably. Thanks for leaving the comments.

HandleType handle() const {
return handle_;
}
const HandleType handle() const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as a purely informational refactor, do you think it would be a good idea to rename this to virHandle() so we avoid mental collisions with v8's handle() ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise I have no issues with this commit, I'll just cherry-pick it right in

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Do you have the time to rename it yourself?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants