سؤال

I've got some custom controls on a dynamically build web page that can have delegates added to their event handlers as the page loads.

If the page is refreshed, do I need to worry about leaking memory due to adding these event handlers each time the page loads, or does everything in the page gets GCd?

I seem to think that the "page" gets gc'd every time it's loaded and the only items that persist are things like session variables, but that comes from when I was doing stuff in PHP. I'm wondering if anyone has anything concrete on this for c#/asp.net.

APPEND:

My delegates are only looking and interacting with specific controls on the page at the time for example, when one control is changed, another control is defaulted to select a corresponding value.

هل كانت مفيدة؟

المحلول

Every time user makes a request to ASP.NET webserver new instance of Page class is created and it walks through the lifecycle. So if you have some properties, they are initialized with their default values. Afterwards the modified Page is being rendered to HTML and returned to the user. It is not completely clear of what delegates you add, so a piece of code may be helpful, but I don't think you should have any problems.

So the Page is recreated, Session data is being taken by the session cookie, Viewstate data by special input hidden field.

Page Life Cycle may be helpful for you: http://msdn.microsoft.com/en-us/library/ms178472(v=vs.100).aspx

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top