Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Removed
- `IsDirty`. With auto-save on it was almost always `false`, and with the background writer it meant "no change is waiting to be handed over", not "everything is on disk". Use `Save()` when you need the data on disk.
- The `BinaryStorage` finalizer. It held no unmanaged resources to release, it never saved anything, and the only thing it did was release the editor-side path lock from the finalizer thread while the main thread could be reading the same set. A storage that is never disposed now keeps that lock until the domain reloads, so dispose your storages, as before.

### Fixed
- Two storages opened through paths that differ only in form (`a/save.dat` and `./a/save.dat`) no longer publish the same file without serializing against each other.
Expand Down
43 changes: 11 additions & 32 deletions src/Runtime/BinaryStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -653,43 +653,25 @@ private static void ThrowIfCollection<T>([CallerMemberName] string action = null

#endregion

#region Dispose Pattern
#region Dispose

/// <summary> Finalizer </summary>
~BinaryStorage()
{
Dispose(false);
}

/// <summary> Disposes the resources used by the storage. </summary>
/// <summary> Writes any unsaved data to disk, disposes the stored collections and releases the storage. </summary>
public virtual void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

/// <summary> Disposes the resources used by the storage. </summary>
/// <param name="disposing">Whether managed resources should be disposed.</param>
private void Dispose(bool disposing)
{
if (IsDisposed)
{
return;
}

if (disposing)
if (AutoSave && _hasUnsavedChanges)
{
if (AutoSave && _hasUnsavedChanges)
{
SaveDataOnDisk(true);
}
else
{
_persistence.Flush();
}
SaveDataOnDisk(true);
}
else
{
_persistence.Flush();
}

// Always dispose IReactiveCollection instances
foreach (var record in _data.Values)
{
UntrackCollectionOf(record);
Expand All @@ -699,13 +681,10 @@ private void Dispose(bool disposing)
OnKeyChanged = null;
OnKeyRemoved = null;

if (disposing)
_data.Clear();
for (var i = 0; i < _supportedTypes.Count; i++)
{
_data.Clear();
for (var i = 0; i < _supportedTypes.Count; i++)
{
_supportedTypes[i].Count = 0;
}
_supportedTypes[i].Count = 0;
}

IsDisposed = true;
Expand Down
Loading