1

I would like to know when the object initialized inside a method gets disposed. My assumption is when the scope of the function ends.

public void foo() {
 new Object1().SomeMethod();
}
Loozer
  • 21
  • 3
  • At the end of the method. – Haytam Sep 05 '19 at 14:34
  • That's right. And it will be collected when the GC thinks it's time to collect. (always assuming `SomeMethod` does not put `this` into some other surviving object). – René Vogt Sep 05 '19 at 14:34
  • 2
    Nothing ever gets disposed unless you use the `using` statement or call Dispose() explicitly. Maybe you meant "collected" instead of "disposed"? [Look here](https://stackoverflow.com/a/17131389/17034) for the gritty details. So not at the end of the method. – Hans Passant Sep 05 '19 at 14:35

0 Answers0