[Solved] Object disposal when there is no variable referencing it


Use the using statement, just like you have shown, yes it is the elegant way

using (var something = Method2())
{
   Method1(something);
}

Or if you will

using (var something = Method2())
   Method1(something);

Anything else would be unusual and confusing (ie disposing it in your method1)… As pointed out by the comments, unless this was some sort of Command/Query Service, or other Dependency that could be injected with a disposable scope

Also, calling wait on anything is suspicious these days

7

solved Object disposal when there is no variable referencing it