Reputation: 1501
I'm wondering when references (specifically ones defined at a class level) go out of scope in .net web applications to better understand when they'd be eligible for garbage collection.
Currently I have code which looks like this:
public class SomeClass
{
Object object = new Object();
protected void Page_Load(object sender, EventArgs e)
{
// some code
}
}
Would object go out of scope after the page loads (and be eligible for garbage collection) or would it be after the user navigates away from the page?
I typically create web applications in PHP so I'd guess that object would be eligible for GC after the page is done loading since it won't know when the user navigates away from the page.
Upvotes: 1
Views: 69
Reputation: 203813
ASP creates a new Page
object whenever a request is made, and it does not hold onto the reference to that Page
object once it sends the response back to the user, so as long as you don't find some way to hold onto a live reference to that Page
object yourself, once the response is sent, the Page
and all objects only accessible through that page become eligible for garbage collection.
Upvotes: 5