Consider the following
using (Entity e = new Entity())
{
goto: Mars
}
Do I have a leak? Not that I'm gonna do such foolishness but just wondering.
Consider the following
using (Entity e = new Entity())
{
goto: Mars
}
Do I have a leak? Not that I'm gonna do such foolishness but just wondering.
Yes Dispose
will be called. using
translates into try/finally
block something like:
try
{
goto Mars;
Console.WriteLine("in try");
}
finally
{
Console.WriteLine("in finally");
}
Mars:
Console.WriteLine("in Mars");
The output from above would be:
in finally
in Mars
You can also test it by creating your own class that implements IDisposable
like:
class MyDisposable : IDisposable
{
public void Dispose()
{
Console.WriteLine("Dispose called");
}
}
and then:
using (MyDisposable myDisposable = new MyDisposable())
{
goto Mars;
}
Mars:
Console.WriteLine("in Mars");
The output would be:
Dispose called
in Mars