Sunday 15 July 2012

c# - Calling Dispose() vs when an object goes out scope/method finishes -


I have a method in which an attempt / hold / block is inside the block, within the block, I declare the SqlDataReader as follows I do:

  SqlDataReader aReader = null; AReader = aCommand.ExecuteReader ();  

In the end, the objects are manually resolved which are set at those square levels. So in the method objects that implement IDisposable, such as SqlDataReader above, do they automatically settle? Closed () is called on a reader (to be settled), as close ()) after the loop is executed for a while to get the contents of the reader. If there is no call to stop, will this object be automatically stopped / disposed when the method is over or the object will be out of the scope?

Edit: I am using the () statement, there are scenarios which are confusing me thanks

thanks

No, objects are not automatically removed when they go outside the scope.

If they collect garbage they also do not guarantee to be disposed of, although many IDisposable objects make sure to help implement a "fallback" final That they are

You are sure that any IDisposable objects are wrapped in a block. >

No comments:

Post a Comment