Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Encrypting Data
Message
From
09/10/2009 07:47:38
 
 
To
09/10/2009 05:47:39
General information
Forum:
Microsoft SQL Server
Category:
Database design
Title:
Miscellaneous
Thread ID:
01428109
Message ID:
01428441
Views:
36
>>Hi,
>>That's what I did (used the syntax - not looked at the ildasm). But isn't this behaviour just because the code path following a return always goes to the end of the method scope thus intrinsically closing any other contained scopes?
>
>
>I have made a small test program - and added the ildasm for TestDispose()
>
>(1) The Console.WriteLine("Dispose") is executed - but is that due to Disposing or the GC ?
>
>If I put a break on [Console.WriteLine("Dispose") ] and look at the stack, it points to the return statement
>
>(2) The ildasm does not look (at least to me) to go through the finally block - IL_0008: leave.s IL_001a
>
>The doc says about leave
>
>The instruction has one integer parameter specifying the offset of the target and works the same way as an unconditional branching instruction except that it empties the evaluation stack before the branching
>

>
>I'm not sure what the 'evaluation stack' is in this context


http://msdn.microsoft.com/en-us/library/system.reflection.emit.opcodes.leave.aspx

The leave instruction is similar to the br instruction, but it can be used to exit a try, filter, or catch block whereas the ordinary branch instructions can only be used in such a block to transfer control within it. The leave instruction empties the evaluation stack and ensures that the appropriate surrounding finally blocks are executed.




>
>namespace BaseTest
>{
>	
>
>	class test2
>	{
>
>		//______________________________________________________________________
>		static void Main()
>		{
>			TestDispose();
>			Console.ReadLine();
>		}
>		//______________________________________________________________________
>		static void TestDispose()
>		{
>
>			using ( var xx = new Mine() )
>			{
>	
>
>				return;
>			}
>			
>		}
>		//______________________________________________________________________
>	}
>
>	class Mine : IDisposable
>	{
>		public void Dispose()
>		{
>			Console.WriteLine("Dispose");
>		}
>	}
>}
>
>
>
>.method private hidebysig static void  TestDispose() cil managed
>{
>  // Code size       28 (0x1c)
>  .maxstack  2
>  .locals init ([0] class BaseTest.Mine xx,
>           [1] bool CS$4$0000)
>  IL_0000:  nop
>  IL_0001:  newobj     instance void BaseTest.Mine::.ctor()
>  IL_0006:  stloc.0
>  .try
>  {
>    IL_0007:  nop
>    IL_0008:  leave.s    IL_001a
>  }  // end .try
>  finally
>  {
>    IL_000a:  ldloc.0
>    IL_000b:  ldnull
>    IL_000c:  ceq
>    IL_000e:  stloc.1
>    IL_000f:  ldloc.1
>    IL_0010:  brtrue.s   IL_0019
>    IL_0012:  ldloc.0
>    IL_0013:  callvirt   instance void [mscorlib]System.IDisposable::Dispose()
>    IL_0018:  nop
>    IL_0019:  endfinally
>  }  // end handler
>  IL_001a:  nop
>  IL_001b:  ret
>} // end of method test2::TestDispose
>
Gregory
Previous
Reply
Map
View

Click here to load this message in the networking platform