❔ dataset memory leak
I found memory leak and I don't understand how to fix it
Test case:
public class MemoryLeaksTest
: AsyncDisposable
{
private readonly FastReport.Report _report;
private readonly ReportOutputParameters _outputParameters;
private const string ReportPath = "ByRequests.frx";
public MemoryLeaksTest()
{
_report = new();
_report.Load( ReportPath );
_outputParameters = new()
{
Format = ReportOutputFormatType.PDF
};
}
protected override void Dispose( bool disposing )
{
if ( disposing )
_report.Dispose();
base.Dispose( disposing );
}
public async Task Run( bool export )
{
using var dataSet = await FillDataSet();
RegisterReportWithDataSet( dataSet );
PrepareReport();
if ( export )
ExportReport();
}
private void ExportReport()
{
_report.Export(
_outputParameters,
$"test_exported_report_{Guid.NewGuid()}" );
Console.WriteLine( @"report was exported" );
}
private void PrepareReport()
{
_report.Prepare();
}
private void RegisterReportWithDataSet( ByRequests dataSet )
{
_report.RegisterData( dataSet );
}
private async Task<ByRequests> FillDataSet()
{
var dataSet = new ByRequests();
for ( var i = 0; i < 1_000_000; i++ )
{
dataSet._ByRequests.AddByRequestsRow(
Status: $"status: {i}",
Visitor: $"visitor {i}",
Operator: $"operator {i}",
HostSubject: $"host_subject {i}",
CreationTime: $"creation_time {i}",
Validity: $"validity {i}",
Number: $"{i}" );
if ( i % 10000 == 0 )
Console.WriteLine( @$"progress: {i / 10000}" );
}
return dataSet;
}
}
public class MemoryLeaksTest
: AsyncDisposable
{
private readonly FastReport.Report _report;
private readonly ReportOutputParameters _outputParameters;
private const string ReportPath = "ByRequests.frx";
public MemoryLeaksTest()
{
_report = new();
_report.Load( ReportPath );
_outputParameters = new()
{
Format = ReportOutputFormatType.PDF
};
}
protected override void Dispose( bool disposing )
{
if ( disposing )
_report.Dispose();
base.Dispose( disposing );
}
public async Task Run( bool export )
{
using var dataSet = await FillDataSet();
RegisterReportWithDataSet( dataSet );
PrepareReport();
if ( export )
ExportReport();
}
private void ExportReport()
{
_report.Export(
_outputParameters,
$"test_exported_report_{Guid.NewGuid()}" );
Console.WriteLine( @"report was exported" );
}
private void PrepareReport()
{
_report.Prepare();
}
private void RegisterReportWithDataSet( ByRequests dataSet )
{
_report.RegisterData( dataSet );
}
private async Task<ByRequests> FillDataSet()
{
var dataSet = new ByRequests();
for ( var i = 0; i < 1_000_000; i++ )
{
dataSet._ByRequests.AddByRequestsRow(
Status: $"status: {i}",
Visitor: $"visitor {i}",
Operator: $"operator {i}",
HostSubject: $"host_subject {i}",
CreationTime: $"creation_time {i}",
Validity: $"validity {i}",
Number: $"{i}" );
if ( i % 10000 == 0 )
Console.WriteLine( @$"progress: {i / 10000}" );
}
return dataSet;
}
}
7 Replies
Console.CancelKeyPress += ( _, _ ) =>
{
Console.Write( @"Exiting" );
Environment.Exit( 0 );
};
var runner = new MemoryLeaksTest()
.Run( export: false );
runner.Dispose();
while ( Console.ReadKey().Key != ConsoleKey.Escape )
{
}
Console.CancelKeyPress += ( _, _ ) =>
{
Console.Write( @"Exiting" );
Environment.Exit( 0 );
};
var runner = new MemoryLeaksTest()
.Run( export: false );
runner.Dispose();
while ( Console.ReadKey().Key != ConsoleKey.Escape )
{
}
I don't understand why but memory doesn't сlear
even if I use dispose
First time I see
AsyncDisposable
class instead of IAsyncDisposable
interfaceI dont think its a problem
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.