dispose

Is there any way to close a StreamWriter without closing its BaseStream?

半腔热情 提交于 2019-11-26 02:58:13
问题 My root problem is that when using calls Dispose on a StreamWriter , it also disposes the BaseStream (same problem with Close ). I have a workaround for this, but as you can see, it involves copying the stream. Is there any way to do this without copying the stream? The purpose of this is to get the contents of a string (originally read from a database) into a stream, so the stream can be read by a third party component. NB : I cannot change the third party component. public System.IO.Stream

What is the promise disposer pattern?

时间秒杀一切 提交于 2019-11-26 01:54:04
问题 I\'ve read about the promise disposer pattern in several places but I can\'t figure out what it is. It was suggested to me to use it in code that looks like: function getDb(){ return myDbDriver.getConnection(); } var users = getDb().then(function(conn){ return conn.query(\"SELECT name FROM users\").finally(function(users){ conn.release(); }); }); What\'s the promise disposer pattern and how does it apply here? Note - in native promises, I shim .finally as \"add both rejection and fulfillment

Finalize vs Dispose

老子叫甜甜 提交于 2019-11-26 01:48:29
问题 Why do some people use the Finalize method over the Dispose method? In what situations would you use the Finalize method over the Dispose method and vice versa? 回答1: Others have already covered the difference between Dispose and Finalize (btw the Finalize method is still called a destructor in the language specification), so I'll just add a little about the scenarios where the Finalize method comes in handy. Some types encapsulate disposable resources in a manner where it is easy to use and

Do you need to dispose of objects and set them to null?

泄露秘密 提交于 2019-11-26 01:26:58
问题 Do you need to dispose of objects and set them to null, or will the garbage collector clean them up when they go out of scope? 回答1: Objects will be cleaned up when they are no longer being used and when the garbage collector sees fit. Sometimes, you may need to set an object to null in order to make it go out of scope (such as a static field whose value you no longer need), but overall there is usually no need to set to null . Regarding disposing objects, I agree with @Andre. If the object is

Should I Dispose() DataSet and DataTable?

偶尔善良 提交于 2019-11-25 22:59:10
问题 DataSet and DataTable both implement IDisposable, so, by conventional best practices, I should call their Dispose() methods. However, from what I\'ve read so far, DataSet and DataTable don\'t actually have any unmanaged resources, so Dispose() doesn\'t actually do much. Plus, I can\'t just use using(DataSet myDataSet...) because DataSet has a collection of DataTables. So, to be safe, I\'d need to iterate through myDataSet.Tables, dispose of each of the DataTables, then dispose of the DataSet.