I talked to a man about the use () statement. He said that if we do not use the using statement () to something like the StreamWriter, if there is any exception, the resource will NEVER be assembled.
Operator using has nothing to do with garbage collection. Once an object has live links, it becomes eligible for garbage collection.
I understand how to use the using statement (), but I do not agree with the fact that life will never be collected.
Oh, then you're right.
I think that with the help of () operator will call the dispose () method at the end that can make the collection more quickly.
He may or may not make the collection more quickly. To dispose method typically cause GC.SupressFinalize(object) , which means that the finalizer will not be called when the object is collected debris. Instead, the object is simply assembled. Thus, it can make the collection more quickly.
If you intend to say that it makes the object collected immediately, and not later, then it will be incorrect. Eligible items are collected every time the garbage collector walks up to him, more than ever, and the object is appropriate, as soon as he has no links to the live links, for which the operator using little effect. In fact, since the finally block to use manual contains a live link, I can imagine a scenario in which it could increase the lifetime of the object, but this effect is not considered, because the lifetime management of the object is not a use-point, determined by the removal of unmanaged resources is point of use statement.
However, even if we do not use use (), we do not call the dispose (), the resource can still be collected by the collection envelope, although it may take much more time.
Again, use Dispose and usually do not affect the lifetime of the object. This affects only the state of unmanaged resources (provided that the Dispose method is implemented correctly). You are right that the object will still be collected.