C
C#2y ago
SWEETPONY

❔ 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
SWEETPONY
SWEETPONYOP2y ago
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 )
{

}
SWEETPONY
SWEETPONYOP2y ago
SWEETPONY
SWEETPONYOP2y ago
I don't understand why but memory doesn't сlear even if I use dispose
SWEETPONY
SWEETPONYOP2y ago
Angius
Angius2y ago
First time I see AsyncDisposable class instead of IAsyncDisposable interface
SWEETPONY
SWEETPONYOP2y ago
I dont think its a problem blobthumbsup
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server