Skip to content

Commit b618c3b

Browse files
committed
Fix: improve memory performance
1 parent 659a779 commit b618c3b

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

DebitExpress.VatRelief/MainWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Diagnostics;
33
using System.IO;
44
using System.Linq;
5-
using System.Reflection;
65
using System.Windows;
76
using DebitExpress.VatRelief.Models;
87
using DebitExpress.VatRelief.Utils;
@@ -118,6 +117,7 @@ private async void OnGenerate(object sender, RoutedEventArgs e)
118117

119118
NotifyResult("Files generated successfully");
120119
OpenFolder(path);
120+
GC.Collect();
121121
}
122122
finally
123123
{

DebitExpress.VatRelief/Utils/DatFileGenerator.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ public async Task<Result> GenerateAsync(ExcelData data, string path)
5151
if (secondMonthPurchases.Count > 0) await generator.GeneratePurchasesAsync(info, secondMonth, secondMonthPurchases, path);
5252
if (thirdMonthPurchases.Count > 0) await generator.GeneratePurchasesAsync(info, thirdMonth, thirdMonthPurchases, path);
5353

54+
firstMonthSales.Clear();
55+
secondMonthSales.Clear();
56+
thirdMonthSales.Clear();
57+
firstMonthPurchases.Clear();
58+
secondMonthPurchases.Clear();
59+
thirdMonthPurchases.Clear();
60+
5461
return new Result();
5562
}
5663

@@ -254,7 +261,7 @@ private async Task WritePurchasesDataAsync(TextWriter file, Info info, DateTime
254261
{
255262
foreach (var item in items)
256263
{
257-
var line = $"D,P,{item.Tin.Strip()}," +
264+
var line = $"D,P,\"{item.Tin.Strip()}\"," +
258265
$"\"{item.RegName}\"," +
259266
$"\"{item.LastName}\"," +
260267
$"\"{item.FirstName}\"," +

DebitExpress.VatRelief/Utils/ExcelReconWriter.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ public Result WriteReconciliationReport(ExcelData data, string path)
7575

7676
workbook.SaveAs(fullPath);
7777

78+
extractedSales.ForceClear();
79+
extractedPurchases.ForceClear();
80+
7881
return new Result();
7982
}
8083
catch (Exception e)

DebitExpress.VatRelief/Utils/Extensions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Text.RegularExpressions;
34

45
namespace DebitExpress.VatRelief.Utils;
@@ -119,4 +120,11 @@ public static DateTime GetEndOfMonth(int year, int month)
119120
var eom = DateTime.DaysInMonth(year + 1, month - lastMonth);
120121
return new DateTime(year + 1, month - lastMonth, eom);
121122
}
123+
124+
public static void ForceClear<T>(this List<T> list)
125+
{
126+
list.Clear();
127+
var id = GC.GetGeneration(list);
128+
GC.Collect(id, GCCollectionMode.Forced);
129+
}
122130
}

0 commit comments

Comments
 (0)