Solved

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

Posted on 2015-01-07
4
125 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:Michael74
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:
Michael74 earned 500 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

756 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