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

Fix runtime crash #4

Merged
merged 1 commit into from
Dec 23, 2020
Merged

Fix runtime crash #4

merged 1 commit into from
Dec 23, 2020

Conversation

bradfitz
Copy link
Contributor

Fixes #2

@bradfitz
Copy link
Contributor Author

/cc @danderson

@bradfitz
Copy link
Contributor Author

PTAL @josharian @danderson

Copy link
Collaborator

@danderson danderson left a comment

Choose a reason for hiding this comment

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

Based on my understanding of what the issue was previously, this fix LGTM.

@bradfitz
Copy link
Contributor Author

Cool. Will submit. @josharian can school us if we're wrong. 😂

@bradfitz bradfitz merged commit 5106680 into main Dec 23, 2020
@bradfitz bradfitz deleted the bradfitz/fix_crash branch December 23, 2020 04:48
@josharian
Copy link
Collaborator

I've been pondering this intermittently. I don't understand the handling of refs. It's not actual refcounting. It seems to me e.g. that the finalizer could set refs = 1 before setting a new finalizer, which could speed up things considerably. Is a bool enough?

@danderson
Copy link
Collaborator

Yeah, while writing docstrings explaining this interplay, I realized that this is not actually refcounting, but something akin to mark-and-sweep. As currently written, the weakref will need one GC cycle per call to Get before the interned value is actually deleted. So, it does still save memory, but the freeing schedule is unpredictable.

I think Josh is right that in the "re-set finalizer" case, we can set refs=1 to speed things up. In that case, a dangling Value will get collected at most 3 GC cycles after its last reference was dropped. I'll send a patch for same alongside the docstrings explaining this. I welcome a bikeshed for a new name for refs, since it's not a refcount.

@bradfitz
Copy link
Contributor Author

It seems to me e.g. that the finalizer could set refs = 1 before setting a new finalizer, which could speed up things considerably.

Yeah, that's a good idea.

Is a bool enough?

Empirically, yes. PR coming.

danderson added a commit to danderson/intern that referenced this pull request Dec 23, 2020
Per discussion in go4org#4.

Signed-off-by: David Anderson <dave@natulte.net>
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.

fatal error: found pointer to free object
3 participants