how to dispose and object nicely.

G

Guest

hello,

i wants objects to be clean up after a page close, either by a button or by
clickingon the x on the top right of the browser.
so in vb.net i would use the finalize method... but how can this be done in
c#? i want a finalize a methond. thanks
 
M

Mark Fitzpatrick

Because of the way the web works, you will never know when a user closes the
browser. The only time that the web server and the browser are connected are
while the browser is fetching the page, they're disconnected once the page
finished loading. After that, they don't talk until the user performs some
action. Your best time to clean up the objects is right after you are
finished with them. You don't have to necessarily clean up all the controls
on a page, but, for example, you would need to make sure that a SqlReader
that is bound to a DataGrid is closed after the DataGrid's DataBind() method
is called and also that the SqlReader is then set to null to help the
garbage collection pick it up. It doesn't matter if this is done in VB.Net
or C#, they both have similar mechanics. The difference you're going to run
into is moving from a Windows Forms environment to an ASP.Net Web Forms
environment, and they often have very different behavior.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top