db will remain until it goes out of scope, all references to it will be lost, and GC decides to attack. Calling Dispose does not clear the object itself; it tells the object to clear whatever it holds.
The IDisposable interface is managing your own resources that the GC cannot manage. The object itself is the managed entity that the GC takes over. In your example, this object probably maintains a connection to the database, which is a native resource.
The GC cannot clear it, so for the deterministic management of this memory / resource, the class implements IDisposable to tell clients "hey, you need to do a little extra work to ensure that the resources that I need to do my work will take care as efficient as possible."
By the way, the correct implementation of IDisposable will result in the release of any native resources in the finalizer, so you should not experience a memory leak if you do not call Dispose . However, this is not deterministic, and you can experience problems very well by doing this. Good practice dictates that you release these resources as soon as possible, which is why you yourself call Dispose .
Ed S. source share