Friday, August 04, 2006

Performance Optimization - Explicitly Dispose or Close all the resources

Explicitly Dispose or Close all the resources: To guarantee resources are cleaned up when an exception occurs, use a try/finally block. Close the resources in the finally clause. Using a try/finally block ensures that resources are disposed even if an exception occurs. Open your connection just before needing it, and close it as soon as you're done with it. Your motto should always be "get in, get/save data, get out." If you use different objects, make sure you call the Dispose method of the object or the Close method if one is provided. Failing to call Close or Dispose prolongs the life of the object in memory long after the client stops using it. This defers the cleanup and can contribute to memory pressure. Database connection and files are examples of shared resources that should be explicitly closed.

Ref : http://www.codeproject.com/useritems/ASPNET_Best_Practices.asp

No comments:

    follow me on Twitter