C# - Dispose Rule
Tips
- All IDisposable objects must be disposed. There are only few exceptions e.g. https://stackoverflow.com/questions/38784434/how-to-properly-dispose-the-stream-when-using-streamcontent
- Use "using" by default for all IDisposable classes. If "using" cannot be used, at least "try ... finally" must be used and dispose inside "finally".
- If a method returns an IDisposable classes, it is the responsibility of the caller to dispose it properly.
- Try to keep IDisposable objects lifetime as short as possible e.g. Bitmap
No comments:
Post a Comment