How to release memory when the report is loaded

Stimulsoft Reports.NET discussion
nn170498
Posts: 6
Joined: Thu Dec 29, 2022 4:08 am

How to release memory when the report is loaded

Post by nn170498 »

I use .NET 7 with Stimulsoft.Reports.Web.NetCore version 2022.4.4.

I loaded a report from a string, then compile and render it. How can I release memory of the report when the report is close ?

I can not dispose in the GetReport function because it need to return StiNetCoreViewer.GetReportResult(this, report);

I tried load from assemblly like :

Code: Select all

 string folder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                            folder = Path.Combine(folder, "Stimulsoft\\CompiledReports");
                            folder = Path.Combine(folder, System.Runtime.InteropServices.RuntimeEnvironment.GetSystemVersion().ToString());

                            System.Console.WriteLine("report.GetReportAssemblyCacheName()" + report.GetReportAssemblyCacheName());
                            string compiledReportFile = Path.Combine(folder, report.GetReportAssemblyCacheName());

                            if (System.IO.File.Exists(compiledReportFile))
                                report = StiReport.GetReportFromAssembly(compiledReportFile, true);
                            else
                            {
                                if (!Directory.Exists(folder)) Directory.CreateDirectory(folder);
                                report.Compile(compiledReportFile);
                            }
But it throw error at report.Compile(compiledReportFile);
Lech Kulikowski
Posts: 6271
Joined: Tue Mar 20, 2018 5:34 am

Re: How to release memory when the report is loaded

Post by Lech Kulikowski »

Hello,

You can use the Interpretation mode for reports:
In the interpretation mode the compilation does not occur. So time and memory is not used. It is very important, especially when a report has a great number of components.

Another method of increasing the speed of report building and reducing memory usage is a compilation of the report as an assembly - .dll file. The main advantage of this method lies in the fact that the compilation occurs only once. The next time already compiled report is loaded. There is one issue with this. When updating to the latest product version, you have to re-compile a report from a template (.mrt file) into the assembly. Otherwise some errors may occur.

Thank you.
nn170498
Posts: 6
Joined: Thu Dec 29, 2022 4:08 am

Re: How to release memory when the report is loaded

Post by nn170498 »

Hello,

Thanks for the response.

My flow is something like this:

1. Load the layout empty from .mrt file
2. Query data by LinQ and RegData
3. Compile

So could I use mode Interpretation ?
Lech Kulikowski
Posts: 6271
Joined: Tue Mar 20, 2018 5:34 am

Re: How to release memory when the report is loaded

Post by Lech Kulikowski »

Hello,

Yes. In this case, the Compile() method is not needed.

Thank you.
nn170498
Posts: 6
Joined: Thu Dec 29, 2022 4:08 am

Re: How to release memory when the report is loaded

Post by nn170498 »

Hello,

However, I also use ViewerInteraction to query by using StiAction.Variables to pass variables into report.Dictionary.Variables.

If I remove the Compile() method, when I click submit, the report does not load the data in UI.
Lech Kulikowski
Posts: 6271
Joined: Tue Mar 20, 2018 5:34 am

Re: How to release memory when the report is loaded

Post by Lech Kulikowski »

Hello,

Could you prepare and send a sample project that reproduces the issue for analysis?

Thank you.
nn170498
Posts: 6
Joined: Thu Dec 29, 2022 4:08 am

Re: How to release memory when the report is loaded

Post by nn170498 »

Hello,

Sorry that I can not prepare a full sample project, but I can give you sample code for previewing:

- In my controller:

Code: Select all

  public async Task<IActionResult> GetReport()
        {
                       var report = StiReport.CreateNewReport();

                        var reportTemplate = "mybase64_mrt_content"
                        if (reportTemplate != null)
                        {
                            var stream = new MemoryStream(Convert.FromBase64String(mybase64_mrt_content));
                            report.Load(stream);
                            
                            var config= GetConfigMyReport();
                            
                            // my dynamic helper will help invoke function to RegData and Compile
                             report = await ReflectionHelper.DynamicInvoke<Task<StiReport>>(config.FullClassName, config.Function);
                             
                             return StiNetCoreViewer.GetReportResult(this, report);
                       }
          }
          
          public async Task<IActionResult> ViewerInteraction()
        {
                        var _report = StiNetCoreViewer.GetReportObject(this);
                StiRequestParams requestParams = StiNetCoreViewer.GetRequestParams(this);

        if (requestParams.Action == StiAction.Variables)
                {

\                    if (requestParams.Interaction.Variables != null && _report.Dictionary.Variables != null)
                        _report.Dictionary.Variables.Clear();
                    foreach (var item in requestParams.Interaction.Variables.Keys)
                    {
                        _report.Dictionary.Variables.Add(item.ToString(), requestParams.Interaction.Variables[item.ToString()]);
\
                    }
                }
		
      var config= GetConfigMyReport();
                            
                            // my dynamic helper will help invoke function to RegData and Compile
                             report = await ReflectionHelper.DynamicInvoke<Task<StiReport>>(config.FullClassName, config.Function);
                             
		return StiNetCoreViewer.InteractionResult(this, _report);
        }
 
- In my class and function code :

Code: Select all

{
var result= MyList;
report.Dictionary.DataSources.Clear();
report.RegData("DataSource", result);
return result;
}
Lech Kulikowski
Posts: 6271
Joined: Tue Mar 20, 2018 5:34 am

Re: How to release memory when the report is loaded

Post by Lech Kulikowski »

Hello,

Unfortunately, it is difficult to say something only by the provided part of the code.

Thank you.
hamzasikveli
Posts: 1
Joined: Sat Mar 16, 2024 11:47 am

Re: How to release memory when the report is loaded

Post by hamzasikveli »

Lech Kulikowski wrote: Tue Mar 12, 2024 8:44 am Hello,

You can use the Interpretation mode for reports:
In the interpretation mode the compilation does not occur. So time and memory is not used. It is very important, especially when a report has a great number of components.

Another method of increasing the speed of report building and reducing memory usage is a compilation of the report as an assembly - .dll file. The main advantage of this method lies in the fact that the compilation occurs only once. The next time already compiled report is loaded. There is one issue with this. When updating to the latest product version, you have to re-compile a report from a template (.mrt file) into the assembly. Otherwise some errors may occur.

Thank you.
Thanks a lot for information Lech
Lech Kulikowski
Posts: 6271
Joined: Tue Mar 20, 2018 5:34 am

Re: How to release memory when the report is loaded

Post by Lech Kulikowski »

Hello,

You are welcome.
Post Reply