diff --git a/Projects/Dotmim.Sync.Core/Batch/BatchPartInfo.cs b/Projects/Dotmim.Sync.Core/Batch/BatchPartInfo.cs index 602b2b908..b84ca3ff2 100644 --- a/Projects/Dotmim.Sync.Core/Batch/BatchPartInfo.cs +++ b/Projects/Dotmim.Sync.Core/Batch/BatchPartInfo.cs @@ -198,7 +198,11 @@ internal static async Task CreateBatchPartInfoAsync(int batchInde // The batch part creation process will serialize the changesSet to the disk // Serialize the file ! - await SerializeAsync(set.GetContainerSet(), fileName, directoryFullPath, serializerFactory, orchestrator); + var containerSet = set.GetContainerSet(); + await SerializeAsync(containerSet, fileName, directoryFullPath, serializerFactory, orchestrator); + + containerSet.Dispose(); + containerSet = null; bpi = new BatchPartInfo { FileName = fileName }; bpi.Index = batchIndex; diff --git a/Projects/Dotmim.Sync.Core/Interceptors/InterceptorWrapper.cs b/Projects/Dotmim.Sync.Core/Interceptors/InterceptorWrapper.cs index 65f20e2f6..4403f1071 100644 --- a/Projects/Dotmim.Sync.Core/Interceptors/InterceptorWrapper.cs +++ b/Projects/Dotmim.Sync.Core/Interceptors/InterceptorWrapper.cs @@ -64,7 +64,7 @@ public async Task RunAsync(T args, CancellationToken cancellationToken) public void Dispose() { this.Dispose(true); - GC.SuppressFinalize(this); + //GC.SuppressFinalize(this); } protected virtual void Dispose(bool cleanup) => this.wrapperAsync = null; diff --git a/Projects/Dotmim.Sync.Core/Orchestrators/RemoteOrchestrator.Snapshots.cs b/Projects/Dotmim.Sync.Core/Orchestrators/RemoteOrchestrator.Snapshots.cs index 1a17b56cb..6bcde3e86 100644 --- a/Projects/Dotmim.Sync.Core/Orchestrators/RemoteOrchestrator.Snapshots.cs +++ b/Projects/Dotmim.Sync.Core/Orchestrators/RemoteOrchestrator.Snapshots.cs @@ -152,10 +152,11 @@ public virtual Task CreateSnapshotAsync(SyncParameters syncParameters if (bptis != null) { // Statistics - var tableChangesSelected = new TableChangesSelected(table.TableName, table.SchemaName); - - // we are applying a snapshot where it can't have any deletes, obviously - tableChangesSelected.Upserts = bptis.Sum(bpti => bpti.RowsCount); + var tableChangesSelected = new TableChangesSelected(table.TableName, table.SchemaName) + { + // we are applying a snapshot where it can't have any deletes, obviously + Upserts = bptis.Sum(bpti => bpti.RowsCount) + }; if (tableChangesSelected.Upserts > 0) changesSelected.TableChangesSelected.Add(tableChangesSelected); @@ -260,7 +261,7 @@ internal virtual async Task InternalCreateSnapshotAsync(SyncContext c var row = this.CreateSyncRowFromReader(dataReader, changesSetTable); // Add the row to the changes set - changesSetTable.Rows.Add(row); + changesSetTable.Rows.Add(row); // Set the correct state to be applied if (row.RowState == DataRowState.Deleted) @@ -292,7 +293,8 @@ internal virtual async Task InternalCreateSnapshotAsync(SyncContext c batchIndex++; // we know the datas are serialized here, so we can flush the set - changesSet.Clear(); + changesSet.Dispose(); + changesSetTable.Dispose(); // Recreate an empty ContainerSet and a ContainerTable changesSet = new SyncSet(); @@ -301,9 +303,12 @@ internal virtual async Task InternalCreateSnapshotAsync(SyncContext c // Init the row memory size rowsMemorySize = 0L; + + GC.Collect(); } dataReader.Close(); + GC.Collect(); // We don't report progress if no table changes is empty, to limit verbosity if (tableChangesSelected.Deletes > 0 || tableChangesSelected.Upserts > 0) diff --git a/Projects/Dotmim.Sync.Core/Set/ContainerSet.cs b/Projects/Dotmim.Sync.Core/Set/ContainerSet.cs index 8cdabb8b7..8a06387ec 100644 --- a/Projects/Dotmim.Sync.Core/Set/ContainerSet.cs +++ b/Projects/Dotmim.Sync.Core/Set/ContainerSet.cs @@ -64,7 +64,7 @@ public void Dispose() { this.Dispose(true); - GC.SuppressFinalize(this); + //GC.SuppressFinalize(this); } protected virtual void Dispose(bool cleanup) diff --git a/Projects/Dotmim.Sync.Core/Set/SyncFilter.cs b/Projects/Dotmim.Sync.Core/Set/SyncFilter.cs index a21801ff1..e3e7656be 100644 --- a/Projects/Dotmim.Sync.Core/Set/SyncFilter.cs +++ b/Projects/Dotmim.Sync.Core/Set/SyncFilter.cs @@ -167,7 +167,7 @@ public override bool EqualsByProperties(SyncFilter other) public void Dispose() { this.Dispose(true); - GC.SuppressFinalize(this); + //GC.SuppressFinalize(this); } protected virtual void Dispose(bool cleanup) diff --git a/Projects/Dotmim.Sync.Core/Set/SyncSet.cs b/Projects/Dotmim.Sync.Core/Set/SyncSet.cs index dc824990f..d8e2c7bda 100644 --- a/Projects/Dotmim.Sync.Core/Set/SyncSet.cs +++ b/Projects/Dotmim.Sync.Core/Set/SyncSet.cs @@ -159,7 +159,7 @@ public void Dispose() if (this.Filters != null) this.Filters.Schema = null; - GC.SuppressFinalize(this); + //GC.SuppressFinalize(this); } protected virtual void Dispose(bool cleanup) @@ -168,13 +168,22 @@ protected virtual void Dispose(bool cleanup) if (cleanup) { if (this.Tables != null) + { this.Tables.Clear(); + this.Tables = null; + } if (this.Relations != null) + { this.Relations.Clear(); + this.Relations = null; + } if (this.Filters != null) + { this.Filters.Clear(); + this.Filters = null; + } } // Dispose unmanaged ressources diff --git a/Projects/Dotmim.Sync.Core/Set/SyncTable.cs b/Projects/Dotmim.Sync.Core/Set/SyncTable.cs index 0536bcc1d..db09f419f 100644 --- a/Projects/Dotmim.Sync.Core/Set/SyncTable.cs +++ b/Projects/Dotmim.Sync.Core/Set/SyncTable.cs @@ -123,7 +123,7 @@ public void EnsureTable(SyncSet schema) public void Dispose() { this.Dispose(true); - GC.SuppressFinalize(this); + //GC.SuppressFinalize(this); } protected virtual void Dispose(bool cleanup) @@ -132,10 +132,16 @@ protected virtual void Dispose(bool cleanup) if (cleanup) { if (this.Rows != null) + { this.Rows.Clear(); + this.Rows = null; + } if (this.Columns != null) + { this.Columns.Clear(); + this.Columns = null; + } this.Schema = null; } diff --git a/Projects/Dotmim.Sync.Core/SyncAgent.cs b/Projects/Dotmim.Sync.Core/SyncAgent.cs index f3ebfba51..d4bad3bc2 100644 --- a/Projects/Dotmim.Sync.Core/SyncAgent.cs +++ b/Projects/Dotmim.Sync.Core/SyncAgent.cs @@ -606,7 +606,7 @@ await Task.Run(async () => public void Dispose() { this.Dispose(true); - GC.SuppressFinalize(this); + //GC.SuppressFinalize(this); } ///