I have this code:
Method1(Method2());
However, Method2 returns an object that needs to be disposed. Here is how I can handle this:
using (var x = Method2())
{
await Method1(x);
}
Method1 and Method2 belong to framework and it is not up to me to change them.
I have number of such cases. For example, Method2 creates HTTP request and Methid1 sends it.
Again, both methods belong to library that I cannot change.
I know if I do not dispose object, Garbage Collector will eventually do this. May be not soon. I am wandering, if may be in case when there is no any variable that references the object (as it will be after Method1 returns), I can count on Garbage Collector to dispose the object immediately, and thus it is ok to use the original short option.