Memory Leak in Telerik Reporting Service

2 posts, 0 answers
  1. Kanoo
    Kanoo avatar
    5 posts
    Member since:
    Mar 2017

    Posted 03 Mar 2018 Link to this post

    I've web application and using AspNetCore 2.0. I'm using Telerik Reporting v12.0.18.125
    I'm facing a memory leak issue in my system. After displaying the Report using Report Viewer the Report object is still in the memory heap and refreshing the report one time create more 3 report instances and it is never removed from the memory.
    I'm using below CustomReportResolver to Resolve the report using DependencyInjection 

    public class CustomReportResolver : IReportResolver
      {
          private readonly IIocResolver iocResolver;
          private readonly IAbpSession abpSession;
     
          public CustomReportResolver(IIocResolver iocResolver,IAbpSession abpSession)
          {
              this.iocResolver = iocResolver;
              this.abpSession = abpSession;
          }
     
          public ReportSource Resolve(string reportId)
          {
              var reportType = Type.GetType(reportId);
     
              if (reportType == null)
                  throw new UserFriendlyException($"Could not find a corresponding report for type '{reportId}'.");
     
              var report = (Report) this.iocResolver.Resolve(reportType);
              var customReport = report as ReportBase;
              if (customReport != null)
              {
                  customReport.TenntId = abpSession.TenantId;
                  customReport.UserId = abpSession.UserId;
                  customReport.IocResolver = this.iocResolver;
              }
     
              var reportSource = new InstanceReportSource {ReportDocument = report};
              return reportSource;
          }
      }

    and this is the ReportsController

    [ApiExplorerSettings(IgnoreApi = true)]
       public class ReportsController : ReportsControllerBase, ITransientDependency
       {
           public ReportsController(IHostingEnvironment environment, IIocResolver iocResolver, IAbpSession abpSession)
           {           
               this.ReportServiceConfiguration =
                  new ReportServiceConfiguration
                  {
                      HostAppId = "Html5DemoApp",
                      Storage = new FileStorage(),
                      ReportResolver = new CustomReportResolver(iocResolver,abpSession)
                  };
           }
       }

    I want to find a way to remove the Report Instance from the memory to avoid this memory leak issue.

    Thanks,

     

  2. Todor
    Admin
    Todor avatar
    396 posts

    Posted 07 Mar 2018 Link to this post

    Hi Kanoo,

    The Report Engine indeed needs more that one instance of the report to resolve parameters, process and render the report in the required format (pdf, doc, etc.) - check Report Life Cycle article.
    Each Refresh/Preview re-generates the report, hence the new instances. The instances are released after the Report Engine has finished using them.

    In .NET you are not supposed to release memory yourself, i.e. you don't get memory leaks in the traditional sense.
    The Report Engine relies on the Garbage Collection to release the memory occupied by report instances. The unused report instance(s) would be eventually collected when/if any of the conditions for Garbage Collection is met.

    Therefore we do NOT consider the creation of more than one instance of the report as a Memory Leak.

    Each report instance occupies a small amount of memory that could hardly be critical for the application.
    However, you are free to explicitly call GC.Collect() method to collect the released report instances. This would slow down the application though.

    Regards,
    Todor
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top