The importance of .Dispose()

I was checking out the Oracle OTN forums last night trying to get some good info on the Oracle Data Provider for .NET (aka ODP.NET).  I ran across a post that reminded me that there is more to be done when writing good .NET code than just depending on the garbage collector.  The postor stated that he was seeing memory allocations that were continually going up for inetinfo/aspnet_wp processes(s).  The person from Oracle stated that this was consistent with not calling the .Dispose() method for each object (OracleConnection, OracleCommand, .....) created with ODP.NET. 

From what I have seen, the lack of calling.Dispose() can sneak up and bite you.  I wrote some code last year that used the Performance Monitor objects to see what was happening with different processes.  I forgot to call the .Dispose() method.  After about four or five days, my code would quit working and give me out of memory errors.  It took me a couple of days before I realized that I had not called .Dispose() to clear up the unmangaged resources.  That's a mistake that has never been made again.

Wally

No Comments