Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Pages not removed from memory

I've been having really bad memory problems with an ASP.NET Application. It seems as if every time the page loads, the old previous instance of the page is not removed from memory. If you press F5 ten times, the memory adds 10-20MB to the instance. During Stress and performance testing, this would max out the memory and the web server will crash...

I ran ANTS memory profiling and it confirmed that every time a page is loaded, the old instane remains in memory. All my ASP.NET Web pages uses a Master page as well. Again, if I load the page 10 times, then 10 instances of the web page exists, as well as 10 instances of the master page...

http://oi51.tinypic.com/21msy2g.jpg

Looking at the ants profiler results, you can see that every page reload adds around 320Kb to the memory, and thats just the web page, not even taking the master page into account. My application is a life insurance app that captures applications, so it goes through about 30-40 pages. So you can see why this is a masssive proble.

How would I go about finding out whats keeping the page in memory? I have no idea where to begin... :\

All my pages uses Unity and Dependency injection to register service... Not sure if I need to unregister these services after during page_onUnload.

EDIT

Okay, I've managed to track the issue down. The reason why the page isn't disposed(GCollected) is because of the Unity service instances that registered but nevered unregistered during the unload of the page. This is how I'm using Unity on my page:

I inject the services through public properties

    #region Services

    [Dependency]
    public ReviewReportService SummaryService { get; set; }

    [Dependency]
    public Portfolios.PortfolioService PortfolioService { get; set; }

    #endregion

Then page init, I do the Unity Buildup:

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

                    ApplicationContainer.BuildUp(this.Context, this);
            }

Now obviously when the page goes through its normal lifecycle and calls Unload, it can't unload because of the dependency injection reference... I'm just not sure how to unregistered the services (SummaryService, PortfolioService )

I tried calling the following in OnUnload but it does nothing:

ApplicationContainer.GetContainer(Context).Teardown(this);

like image 578
FaNIX Avatar asked Nov 13 '22 18:11

FaNIX


1 Answers

You have a static reference to the Page somewhere and it can't be disposed.

like image 91
rick schott Avatar answered Dec 17 '22 20:12

rick schott