release of resources

Stimulsoft Reports.WEB discussion
Post Reply
r.bianco
Posts: 75
Joined: Thu Oct 27, 2016 2:06 pm

release of resources

Post by r.bianco »

Reports.Web 2020.4.1.0

Good morning,
in the web application where we use the stimulsoft reports we have a problem of non-deallocated memory.
The report is displayed through the StiWebViewer object, in a new browser tab.
We would like to be able to intercept the closing of the browser tab to ask the StiWebViewer object to release the resources.
How you do it?
Soft System srl
Lech Kulikowski
Posts: 6245
Joined: Tue Mar 20, 2018 5:34 am

Re: release of resources

Post by Lech Kulikowski »

Hello,

You can use the static method for clear all data caches:
StiCacheCleaner.Clean(report);

You can use this method to force the current report to be deleted from the server cache:
var cacheGuid = $"{e.RequestParams.Id}_{e.RequestParams.Cache.ClientGuid}";
StiWebViewer.CacheHelper.RemoveReport(cacheGuid);

You can also change the caching method by overriding a special StiCacheHelper class - see documentation for more details:
https://www.stimulsoft.com/en/documenta ... ashing.htm

Thank you.
r.bianco
Posts: 75
Joined: Thu Oct 27, 2016 2:06 pm

Re: release of resources

Post by r.bianco »

Unfortunately it doesn't seem like a cache problem.
I wish I could destroy the report object when the user closes the browser tab that contains the object.

In other words, when the user closes the browser tab, I would like to run this code:

Code: Select all

myReport.Dispose();
myReport = null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
How do I intercept the closing of the tab?
Soft System srl
Lech Kulikowski
Posts: 6245
Joined: Tue Mar 20, 2018 5:34 am

Re: release of resources

Post by Lech Kulikowski »

Hello,

You can subscribe to a JavaScript event in your browser 'beforeunload', and there to send a request to the server, which will call the method with your code.

Thank you.
r.bianco
Posts: 75
Joined: Thu Oct 27, 2016 2:06 pm

Re: release of resources

Post by r.bianco »

In the aspx page there is the StiWebViewer object:

Code: Select all

<cc2:StiWebViewer ID="StiWebViewer1" runat="server" OnReportDesign="StiWebViewer1_ReportDesign" />
Via Javascript, how do I activate an event of the StiWebViewer1 object?
Soft System srl
Lech Kulikowski
Posts: 6245
Joined: Tue Mar 20, 2018 5:34 am

Re: release of resources

Post by Lech Kulikowski »

Hello,

Which event do you want to activate? If you are referring to an earlier event, the viewer does not support such functionality.

Thank you.
r.bianco
Posts: 75
Joined: Thu Oct 27, 2016 2:06 pm

Re: release of resources

Post by r.bianco »

My goal is: to execute the memory deallocation code when the user closes the browser tab which contains the StiWebViewer object.
Something like:

in aspx file

Code: Select all

        <cc2:StiWebViewer ID="StiWebViewer1" runat="server" OnReportDesign="StiWebViewer1_ReportDesign" OnDisposed="StiWebViewer1_Disposed"/>

		<script>
            window.beforeunload = function () {
                this.jsObject.postAction("Disposed");
			};
		</script>
in aspx.cs file

Code: Select all

    protected void StiWebViewer1_Disposed(object sender, EventArgs e)
    {
        using (StreamWriter file =
            new StreamWriter(sLog, true))
        {
            file.WriteLine("Unload");
        }

        StiReport myReport = StiWebViewer1.Report;
        myReport.Dispose();
        myReport = null;

        //Forza il garbage collector a liberare la memoria allocata dall'assembly e dai dati
        GC.Collect();
        GC.WaitForPendingFinalizers();
        GC.Collect();
    }

Unfortunately, the Disposed event does not trigger.
Should I use a different event?
Should I write the JavaScript code differently?
Soft System srl
Lech Kulikowski
Posts: 6245
Joined: Tue Mar 20, 2018 5:34 am

Re: release of resources

Post by Lech Kulikowski »

Hello,

Unfortunately, the viewer does not support such functionality.

Thank you.
r.bianco
Posts: 75
Joined: Thu Oct 27, 2016 2:06 pm

Re: release of resources

Post by r.bianco »

OK thanks anyway.
Soft System srl
Andrew
Posts: 4104
Joined: Fri Jun 09, 2006 3:58 am

Re: release of resources

Post by Andrew »

You are welcome!
Post Reply