Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2015-01-07
4
Medium Priority
?
135 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
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

926 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