Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to clean up page variables when user closes the web page?

Posted on 2015-01-07
4
Medium Priority
?
133 Views
Last Modified: 2015-01-08
Hi, I'm using vs2012.
I have several variables declared under the page class, public partial class _Default : Page

What's the best way to dispose() or clean up these variables?  I tried accessing them from Global.asax.cs in the Applicaiton-End event but I wasn't able to access these variables when I type in namesapce._Default.  None of the variables show up.
How to clean these up?
Thank you.
0
Comment
Question by:lapucca
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 23

Expert Comment

by:Michael Fowler
ID: 40536925
If they are declared inside the page object then they should go out of scope and be destroyed when the page unloads but if you want to handle this yourself then use the Page.Unload event
http://msdn.microsoft.com/en-us/library/system.web.ui.control.unload(v=vs.110).aspx
0
 

Author Comment

by:lapucca
ID: 40538556
These are variables/properties declare in the page object right after this loc
 public partial class _Default : Page

I have generic collection, about 20-100 objects. So would you recommend to let it go out of scope and garbage collector does its thing or calling the page.unload event to clean up? Thank you.
0
 
LVL 23

Accepted Solution

by:
Michael Fowler earned 2000 total points
ID: 40538633
.Net has pretty good GC algorithms and so unless it is unmanaged eg COM then I would the GC to the system and set the scope appropiately
0
 

Author Comment

by:lapucca
ID: 40538680
Sounds good.  Thank you.
0

Featured Post

Application Discovery Service in AWS

In the era of the cloud, customers migrating away from their existing on-premise infrastructure. This requires lots of planning, strategies, and effort to identify their existing resources and determine how best to migrate.  Datacenter migrations happen in four phases -

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question