dispose

Should I bother calling dispose on objects which share lifetime of process?

亡梦爱人 提交于 2019-12-04 03:24:24
I am aware that all objects which implement IDisposable should be disposed of as soon as they are no longer needed in order to free the memory used by their unmanaged resources. My question relates to objects which I know for a fact will live until the host process itself is terminated. Would it make any difference if I dispose of them or not? Is there any chance of memory not being freed when the process dies? What about GDI objects? Would the GDI handles be freed when the process dies even if they were not disposed? I fully understand that it is good practice to dispose of all objects

How do I safely dispose a System.Timers.Timer?

馋奶兔 提交于 2019-12-04 03:03:52
问题 When you dispose a “raw” .net timer, you can pass in a wait handle to be called once the Win32 timer has been destroyed and you can them assume that your call back will not be called. (And the timer will be considered "dead" by the GC) How do I do this with a System.Timers.Timer? 回答1: As System.Timers.Timer and System.Windows.Forms.Timer both use the ThreadPool it doesn't have a handle to an operating system timer, so there is no native timer resource that's disposed of - just a completed

SqlCommand (Using Statement / Disposing issue)

帅比萌擦擦* 提交于 2019-12-04 02:34:51
Take the following example... Using cn As New SqlConnection(ConnectionString) Try Dim cmd As SqlCommand = New SqlCommand With cmd .Connection = cn .Connection.Open() .CommandText = "dbo.GetCustomerByID" .CommandType = CommandType.StoredProcedure .Parameters.Add("@CustomerID", SqlDbType.Int, 4) .Parameters("@CustomerID").Value = CustomerID End With da = New SqlDataAdapter(cmd) da.Fill(ds, "Customer") Catch ex As Exception End Try End Using From my research today is sounds as though this is basically okay but the SqlCommand is not being disposed of. Question -> Which of the following examples is

When would dispose method not get called?

喜你入骨 提交于 2019-12-04 01:24:14
问题 I was reading this article the other day and was wondering why there was a Finalizer along with the Dispose method. I read here on SO as to why you might want to add Dispose to the Finalizer. My curiousity is, when would the Finalizer be called over the Dispose method itself? Is there a code example or is it based on something happening on the system the software is running? If so, what could happen to not have the Dispose method run by the GC. 回答1: The purpose of the finaliser here is simply

When should I manually dispose of controls? How do I know if a control implements IDisposable?

一个人想着一个人 提交于 2019-12-03 22:28:10
In a previous question about ridding the system tray of an old NotifyIcon I was told that I should Dispose anything that implements IDisposable. Sounds like good practise to me however as a newbie it raises more questions :-) How do I know if a control implements IDisposable? Should I build a class that attempts to dispose everything on all my forms in the formclosed event? Something like this?(psuedocode): foreach(control cont in form) { try{cont.Dispose()} catch{} } If not, then how do I know what controls I would need to manually dispose, or should I simply watch for unusual behaviour

Ninject and DataContext disposal

。_饼干妹妹 提交于 2019-12-03 22:20:38
I'm using Ninject to retrieve my DataContext from the kernel and I was wondering if Ninject automatically disposes the DataContext, or how he handles the dispose() behaviour. From own experiences I know disposing the datacontext is pretty important and that whenever you create a direct object of the DataContext (as in: new DataContext()) you should use a using() block. My question thus is: When im retrieving my DataContext from the kernel, should I still have to use a using() block? Or does Ninject fix this for me? I am investigating this for my colleague Bas. I was looking in the Ninject 2

Cross Method Dispose Patterns in SharePoint

佐手、 提交于 2019-12-03 16:25:17
I've written a class that does various modification to the contents of a SharePoint site. Inside that class, I've implemented a lazy resolved property private SPWeb rootSite { get { if ( _site == null ) { SPSite site = new SPSite( _url ); _site = site.OpenWeb(); } return _site; } } Both the SPSite and the SPWeb need to be disposed, and according to the Best Practices document this situation is called a Cross Method Dispose Pattern... only they don't give any actual suggestion on how to implement the dispose part of the pattern. I opted to have my class implement IDisposable (disposing the site

Proper way to dispose screens in Libgdx

ε祈祈猫儿з 提交于 2019-12-03 13:50:56
What is the proper way of completely disposing of a screen in Libgdx? Currently If I click where a button was on my previous screen the button still does what it would of done if I were on that screen. Should I be .dispose() -ing everything I can in the dispose() method? or is there a simpler way to dispose of everything on screen? Unfortunately there is no easier way. These classes do not share any kind of common " Disposable " interface, or anything like that, to do it automatically. Everything that has a dispose() method needs to be disposed manually when it's not needed anymore. This is

Correct disposing using Repository and Unit Work patterns with Entity Framework?

a 夏天 提交于 2019-12-03 12:25:49
问题 Cheers!I have some doubts about using Unit of Work with Repository. Specially a role of child context from Entity Framework. I have searched a lot of information about this theme, but all that I found just different types of using patterns, I'm confused and I can't understand main think. 1.Where I should realize disposing and saving? -Is it correctly realize Disposable in Inheritance class of DbContext? After that realize in Repository and Unit of Work or just in Uni fo Work? -Where put

Dispose question

不想你离开。 提交于 2019-12-03 11:49:51
I have a number of classes which have private member variables that implement IDisposable (timers, brushes, etc). Do I need to do anything to ensure these variables are cleaned up properly by the .NET Framework? The literature I've come across is referring to "managed resources" vs. "unmanaged resources". These terms are confusing to me because you can have a managed class which implements functionality using unmanaged resources. Is that considered an "unmanaged resource" or "managed resource" ? My understanding is if you aren't calling Dispose() on an object that implements IDisposable, then