Skip to content

Commit 3d6f76c

Browse files
committed
fix leak memory issue in snap creation
1 parent 4b783e3 commit 3d6f76c

File tree

8 files changed

+37
-13
lines changed

8 files changed

+37
-13
lines changed

Projects/Dotmim.Sync.Core/Batch/BatchPartInfo.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,11 @@ internal static async Task<BatchPartInfo> CreateBatchPartInfoAsync(int batchInde
198198
// The batch part creation process will serialize the changesSet to the disk
199199

200200
// Serialize the file !
201-
await SerializeAsync(set.GetContainerSet(), fileName, directoryFullPath, serializerFactory, orchestrator);
201+
var containerSet = set.GetContainerSet();
202+
await SerializeAsync(containerSet, fileName, directoryFullPath, serializerFactory, orchestrator);
203+
204+
containerSet.Dispose();
205+
containerSet = null;
202206

203207
bpi = new BatchPartInfo { FileName = fileName };
204208
bpi.Index = batchIndex;

Projects/Dotmim.Sync.Core/Interceptors/InterceptorWrapper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public async Task RunAsync(T args, CancellationToken cancellationToken)
6464
public void Dispose()
6565
{
6666
this.Dispose(true);
67-
GC.SuppressFinalize(this);
67+
//GC.SuppressFinalize(this);
6868
}
6969

7070
protected virtual void Dispose(bool cleanup) => this.wrapperAsync = null;

Projects/Dotmim.Sync.Core/Orchestrators/RemoteOrchestrator.Snapshots.cs

+11-6
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,11 @@ public virtual Task<BatchInfo> CreateSnapshotAsync(SyncParameters syncParameters
152152
if (bptis != null)
153153
{
154154
// Statistics
155-
var tableChangesSelected = new TableChangesSelected(table.TableName, table.SchemaName);
156-
157-
// we are applying a snapshot where it can't have any deletes, obviously
158-
tableChangesSelected.Upserts = bptis.Sum(bpti => bpti.RowsCount);
155+
var tableChangesSelected = new TableChangesSelected(table.TableName, table.SchemaName)
156+
{
157+
// we are applying a snapshot where it can't have any deletes, obviously
158+
Upserts = bptis.Sum(bpti => bpti.RowsCount)
159+
};
159160

160161
if (tableChangesSelected.Upserts > 0)
161162
changesSelected.TableChangesSelected.Add(tableChangesSelected);
@@ -260,7 +261,7 @@ internal virtual async Task<BatchInfo> InternalCreateSnapshotAsync(SyncContext c
260261
var row = this.CreateSyncRowFromReader(dataReader, changesSetTable);
261262

262263
// Add the row to the changes set
263-
changesSetTable.Rows.Add(row);
264+
changesSetTable.Rows.Add(row);
264265

265266
// Set the correct state to be applied
266267
if (row.RowState == DataRowState.Deleted)
@@ -292,7 +293,8 @@ internal virtual async Task<BatchInfo> InternalCreateSnapshotAsync(SyncContext c
292293
batchIndex++;
293294

294295
// we know the datas are serialized here, so we can flush the set
295-
changesSet.Clear();
296+
changesSet.Dispose();
297+
changesSetTable.Dispose();
296298

297299
// Recreate an empty ContainerSet and a ContainerTable
298300
changesSet = new SyncSet();
@@ -301,9 +303,12 @@ internal virtual async Task<BatchInfo> InternalCreateSnapshotAsync(SyncContext c
301303

302304
// Init the row memory size
303305
rowsMemorySize = 0L;
306+
307+
GC.Collect();
304308
}
305309

306310
dataReader.Close();
311+
GC.Collect();
307312

308313
// We don't report progress if no table changes is empty, to limit verbosity
309314
if (tableChangesSelected.Deletes > 0 || tableChangesSelected.Upserts > 0)

Projects/Dotmim.Sync.Core/Set/ContainerSet.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void Dispose()
6464
{
6565
this.Dispose(true);
6666

67-
GC.SuppressFinalize(this);
67+
//GC.SuppressFinalize(this);
6868
}
6969

7070
protected virtual void Dispose(bool cleanup)

Projects/Dotmim.Sync.Core/Set/SyncFilter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public override bool EqualsByProperties(SyncFilter other)
167167
public void Dispose()
168168
{
169169
this.Dispose(true);
170-
GC.SuppressFinalize(this);
170+
//GC.SuppressFinalize(this);
171171
}
172172

173173
protected virtual void Dispose(bool cleanup)

Projects/Dotmim.Sync.Core/Set/SyncSet.cs

+10-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public void Dispose()
159159
if (this.Filters != null)
160160
this.Filters.Schema = null;
161161

162-
GC.SuppressFinalize(this);
162+
//GC.SuppressFinalize(this);
163163
}
164164

165165
protected virtual void Dispose(bool cleanup)
@@ -168,13 +168,22 @@ protected virtual void Dispose(bool cleanup)
168168
if (cleanup)
169169
{
170170
if (this.Tables != null)
171+
{
171172
this.Tables.Clear();
173+
this.Tables = null;
174+
}
172175

173176
if (this.Relations != null)
177+
{
174178
this.Relations.Clear();
179+
this.Relations = null;
180+
}
175181

176182
if (this.Filters != null)
183+
{
177184
this.Filters.Clear();
185+
this.Filters = null;
186+
}
178187
}
179188

180189
// Dispose unmanaged ressources

Projects/Dotmim.Sync.Core/Set/SyncTable.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public void EnsureTable(SyncSet schema)
123123
public void Dispose()
124124
{
125125
this.Dispose(true);
126-
GC.SuppressFinalize(this);
126+
//GC.SuppressFinalize(this);
127127
}
128128

129129
protected virtual void Dispose(bool cleanup)
@@ -132,10 +132,16 @@ protected virtual void Dispose(bool cleanup)
132132
if (cleanup)
133133
{
134134
if (this.Rows != null)
135+
{
135136
this.Rows.Clear();
137+
this.Rows = null;
138+
}
136139

137140
if (this.Columns != null)
141+
{
138142
this.Columns.Clear();
143+
this.Columns = null;
144+
}
139145

140146
this.Schema = null;
141147
}

Projects/Dotmim.Sync.Core/SyncAgent.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ await Task.Run(async () =>
606606
public void Dispose()
607607
{
608608
this.Dispose(true);
609-
GC.SuppressFinalize(this);
609+
//GC.SuppressFinalize(this);
610610
}
611611

612612
/// <summary>

0 commit comments

Comments
 (0)