Skip to content

Commit

Permalink
Added some housekeeping for memory optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
sorengranfeldt committed Mar 2, 2017
1 parent 92a02ba commit 5132056
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
17 changes: 16 additions & 1 deletion Granfeldt.SQL.MA/MA/Sql.MA.ImportDetached.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
// march 2, 2017, soren granfeldt
// -added disposable of dataset and lists after import

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
Expand Down Expand Up @@ -208,6 +211,8 @@ IEnumerable<CSEntryChange> DataSetToCsEntryChanges(DataSet records)
{
csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(attr.Name, mvs));
}
mvs.Clear();
mvs = null;
}
}
}
Expand Down Expand Up @@ -267,6 +272,8 @@ public OpenImportConnectionResults OpenImportConnectionDetached(KeyedCollection<
parameters.Add(new SqlParameter("importtype", ImportType.ToString()));
parameters.Add(new SqlParameter("customdata", CustomData));
methods.RunStoredProcedure(Configuration.ImportCommandBefore, parameters);
parameters.Clear();
parameters = null;
}
}
catch (Exception ex)
Expand Down Expand Up @@ -319,6 +326,11 @@ public GetImportEntriesResults GetImportEntriesDetached(GetImportEntriesRunStep
DataSet records;
records = methods.ReadObjects(sqlbatch);
importCsEntryQueue.AddRange(DataSetToCsEntryChanges(records));
records.Clear();
records.Dispose();

sqlbatch.Clear();
sqlbatch = null;
}

// return this batch
Expand Down Expand Up @@ -364,13 +376,16 @@ public CloseImportConnectionResults CloseImportConnectionDetached(CloseImportCon
parameters.Add(new SqlParameter("importtype", ImportType.ToString()));
parameters.Add(new SqlParameter("customdata", CustomData));
methods.RunStoredProcedure(Configuration.ImportCommandAfter, parameters);
parameters.Clear();
parameters = null;
}
methods.CloseConnection();
if (importAnchors != null)
{
importAnchors.Clear();
importAnchors = null;
}
GC.Collect();
}
catch (Exception ex)
{
Expand Down
5 changes: 0 additions & 5 deletions Granfeldt.SQL.MA/Tracer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Diagnostics;
using System.Text;

namespace Granfeldt
{
Expand Down Expand Up @@ -35,13 +34,9 @@ public static void Enter(string entryPoint)
{
TraceInformation("enter {0}", entryPoint);
Indent();
Process currentProc = Process.GetCurrentProcess();
Tracer.TraceInformation("memory-usage {0:n0}Kb, private memomry {1:n0}Kb", GC.GetTotalMemory(true) / 1024, currentProc.PrivateMemorySize64 / 1024);
}
public static void Exit(string entryPoint)
{
Process currentProc = Process.GetCurrentProcess();
Tracer.TraceInformation("memory-usage {0:n0}Kb, private memory {1:n0}Kb", GC.GetTotalMemory(true) / 1024, currentProc.PrivateMemorySize64 / 1024);
Unindent();
TraceInformation("exit {0}", entryPoint);
}
Expand Down

0 comments on commit 5132056

Please sign in to comment.