Skip to content

refactor: drop the storage finalizer - #92

Open
imurashka wants to merge 1 commit into
ivan/dedupe-storage-internalsfrom
ivan/drop-storage-finalizer
Open

refactor: drop the storage finalizer#92
imurashka wants to merge 1 commit into
ivan/dedupe-storage-internalsfrom
ivan/drop-storage-finalizer

Conversation

@imurashka

Copy link
Copy Markdown
Contributor

Stacked on #91, so this diff shows only the finalizer change. GitHub retargets it to main once #91 merges.

BinaryStorage holds no unmanaged resources: a dictionary, records, reactive collections, and a persistence layer whose only FileStream is opened and closed inside a single method. The finalizer arrived in #33, a documentation commit, as part of laying out the textbook dispose pattern - nothing asked for it.

On the finalizer thread it skipped the save, then disposed reactive collections that were already unreachable and had no finalizers of their own, and finally released the editor path lock by mutating a static HashSet<string> with no lock while the main thread could be reading the same set from Construct. In player builds that last call is compiled out entirely, so the whole pass was dead work there.

With the finalizer gone, disposing is always true, so Dispose(bool) folds back into Dispose().

Behaviour change: a storage that is never disposed no longer has its editor path lock released by the GC, so a second Construct on the same path will keep throwing until the domain reloads. Nothing changes for storages that are disposed, and no unsaved data was ever written by the finalizer.

BinaryStorage holds no unmanaged resources, so the finalizer had nothing to
release. It skipped the save, disposed collections that were already
unreachable, and released the editor path lock by mutating a static HashSet
from the finalizer thread while the main thread could be reading it from
Construct.

With the finalizer gone, disposing is the only path, so Dispose no longer
needs the disposing flag or the two branches it guarded.
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.

1 participant