Garbage collection works automatically on any managed memory resources. However, sometimes there are classes that use unmanaged memory or special resources without memory, such as file descriptors that need to be freed.
Entity Framework contexts access connections from a common connection pool and need to be informed when they can refuse these connections because they will no longer be used.
Is it correct that Dispose () should be used when loading from a database, but not into regular object assignments?
The Dispose method should only be implemented by classes that can use unmanaged memory or non-memory resources. If a class implements the IDisposable interface, you should always call it Dispose when you are done with this object.
source share