This is really cool thing I got it from my colleage …heres the link.
A few highlights from the same:
1.“If your object has a Dispose method, call it as soon as you are done with the object.”
2.WARNING: Do not write code like this or your hair may fall out, your peers will likely laugh at you, and your code will certainly be suboptimal.
You could also have used simply:
3.Note: you will need to make sure that you build a release optimized version of your assembly (i.e. without debug settings). When the runtime encounters a debug assembly, it intentionally prolongs the lifetime of managed objects through the entire scope of a method call to ease debugging. As a result, the runtime keeps the file open through the entire method, and won’t free it up after it’s last use.
Filed under: Uncategorized