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

Reference counting and accidental copy prevention for Impl classes #503

Merged
merged 2 commits into from
Sep 17, 2024

Conversation

kring
Copy link
Member

@kring kring commented Sep 6, 2024

Reference Counting

Previously, C# objects backed by a native "Impl" object had strict ownership of the Impl instance. It was new'd in the constructor, and delete'd in the finalizer. This was mostly fine, but there are a few cases (mostly related to Future continuations) where it's important to keep the Impl instance alive even though the C# instance might get finalized. See #499. Previously this was not really possible because of the strict ownership. In this PR, Impl instances are internally reference counted, so their lifetime can be managed with an IntrusivePointer.

Note that I haven't actually done anything to take advantage of this in this PR. This PR is just the mostly-mechanical refactoring to reference counting.

Copy prevention

This PR also makes it impossible to accidentally copy Impl classes by declaring deleted constructors and assignment operators. Accidental copying has been responsible for at least one bug in the past, and it was really simple to do this as part of the reference counting change, so I did.

Fixes #223

@j9liu
Copy link
Contributor

j9liu commented Sep 17, 2024

Looks good to me @kring . Not sure what is the best way to test this, but at the very least I built and ran the branch, and connected to Cesium ion with no issues.

@j9liu j9liu merged commit b526595 into main Sep 17, 2024
7 checks passed
@j9liu j9liu deleted the ref-counted-impls branch September 17, 2024 21:33
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.

Disable copy constructor / assignment operator on *Impl classes
2 participants