Page 1 of 1

release of resources

Posted: Mon Oct 05, 2020 12:48 pm
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?

Re: release of resources

Posted: Mon Oct 05, 2020 2:01 pm
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.

Re: release of resources

Posted: Tue Oct 06, 2020 9:24 am
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?

Re: release of resources

Posted: Wed Oct 07, 2020 6:54 am
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.

Re: release of resources

Posted: Wed Oct 07, 2020 1:09 pm
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?

Re: release of resources

Posted: Wed Oct 07, 2020 1:53 pm
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.

Re: release of resources

Posted: Wed Oct 07, 2020 2:42 pm
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?

Re: release of resources

Posted: Thu Oct 08, 2020 6:49 am
by Lech Kulikowski
Hello,

Unfortunately, the viewer does not support such functionality.

Thank you.

Re: release of resources

Posted: Thu Oct 08, 2020 6:58 am
by r.bianco
OK thanks anyway.

Re: release of resources

Posted: Thu Oct 08, 2020 8:04 am
by Andrew
You are welcome!