dispose

System::IDisposable woes

public ref class ScriptEditor : public Form { public: typedef map<UInt32, ScriptEditor^> AlMap; static AlMap AllocationMap; Form^ EditorForm; RichTextBox^ EditorBox; Status...

Properly dispose QuickTime control

Hi, I'm currently developing an application for Windows platform that will be able to play Quick Time videos. The targeted OS versions are Windows XP, Windows Vista and Windows 7. I successfully used the Apple ActiveX QuickTime Control 2.0 (in C#) and everything works well on Windows XP. However, on Vista and Windows 7 I'm facing prob...

How do I manually Dispose RSACryptoServiceProvider?

I have read on MSDN(see Important note) that RSACryptoServiceProvider must be disposed. They give the example: using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider()) Now I'm trying to include RSACryptoServiceProvider into MyClass making use of it in several Methods. With this setup I cannot use the using statement. Ins...

Disposing of Objects with long living dependencies

public class ABC { public ABC(IEventableInstance dependency) { dependency.ANewEvent += MyEventHandler; } private void MyEventHandler(object sender, EventArgs e) { //Do Stuff } } Let us say that an instance of ABC is a long living object and that my dependency is an even longer running object. W...

Difference in declaring IDisposable member in using block or at using block declaration?

Hi, I have the code below: using (SqlCommand command = new SqlCommand()) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Connection = new SqlConnection(); command.CommandText = ""; command.Parameters.Add(new SqlParameter("@ExperienceLevel", 3).Direction = System.Data.Pa...

How can I dispose of an object (say a Bitmap) when it becomes orphaned ?

I have a class A providing Bitmaps to other classes B, C, etc. Now class A holds its bitmaps in a ring queue so after a while it will lose reference to the bitmap. While it's still in the queue, the same Bitmap can be checked out by several classes so that, say, B and C can both hold a reference to this same Bitmap. But it can also hap...

Class Destructor Problem

I am making a simple class that contains a StreamWrite class Logger { private StreamWriter sw; private DateTime LastTime; public Logger(string filename) { LastTime = DateTime.Now; sw = new StreamWriter(filename); } public void Write(string s) { sw.WriteLine((DateTime.Now-LastTime...

disposing a class loader

I am using a custom class loader which extends URLClassLoader. I load some classes into my custom class loader and perform some task. Once the task is completed i want to dispose of the class loader. I tried doing that by setting the reference to null. But this does not garbage collect the class loader. Is there a way that can help wha...

Should I use IDisposable for purely managed resources?

Here is the scenario: I have an object called a Transaction that needs to make sure that only one entity has permission to edit it at any given time. In order to facilitate a long-lived lock, I have the class generating a token object that can be used to make the edits. You would use it like this: var transaction = new Transaction();...

Why do threads waiting on a ManualResetEvent continue waiting even when Close() is called?

We were surprised to learn today that threads waiting on a ManualResetEvent continue waiting on the event even when it's closed. We would have expected that calling Close() would implicitly signal the waiting threads. We tracked this down as a reason some of our windows services were not shutting down as fast as we'd like. We're chang...

Do I need to Dispose to deregister events?

Say I have two classes, and neither of them are GUI components. Class A is a short lived object that registers for an event declared by a long lived object B. For example public A(B b) { b.ChangeEvent += OnChangeEvent; } If A never deregisters from B's event, will A never be garbage collected? Does A need a Dispose method just t...

Is closing/disposing an SqlDataReader needed if you are already closing the SqlConnection?

I noticed This question, but my question is a bit more specific. Is there any advantage to using using (SqlConnection conn = new SqlConnection(conStr)) { using (SqlCommand command = new SqlCommand()) { // dostuff } } instead of using (SqlConnection conn = new SqlConnection(conStr)) { SqlCommand command =...

How to dispose the objects created by factory pattern

Hi, I am using Factory pattern to create .NET objects of a class. I also need to make sure that all such objects should be disposed before application terminates. Where and How can I dispose the objects created by factory pattern? Shall I dispose in the class in which I am getting the objects created by factory? ...

Dispose Form opened in MainForm tab

Hi, I have a MainForm which has tab Control and several independent form. I open each Individual From in the tab of the main form. A "Close Tab" button on the MainFrom closes the current tab, its implementation is below. This closes the current tab but what I also need is to dispose the From whose tab is closed but I am not sure how to ...

Is it possible to force the use of "using" for disposable classes?

I need to force the use of "using" to dispose a new instance of a class. public class MyClass : IDisposable { ... } using(MyClass obj = new MyClass()) // Force to use "using" { } ...

JFace FontRegistry Font Disposal

I have an application which will have many windows, so it makes sense to me to create a singleton that holds a FontRegistry instance and have that singleton manage the FontRegistry's contents. My code looks something like this: import org.eclipse.jface.resource.FontRegistry; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.w...

Why "Finalize method should not reference any other objects" ?

I have been pondering why it is recommended that we should not release managed resources inside finalize. If you see the code example at http://msdn.microsoft.com/en-us/library/system.gc.suppressfinalize.aspx , and search for string "Dispose(bool disposing) executes in two distinct scenarios" and read that comment, you will understand w...

Proper disposing of class implementing IDisposable

Which one of the below 2 code pieces is not calling dispose and therefore is bad practice: ... using(SomeIDisposable p = new SomeIDisposable()) { return p.GetSomething(...); } ... or ... return new SomeIDisposable().GetSomething(...); ... ? ...

.Net: Is this correct: objSample.dispose() means objSample = null ?

Hi Just wanna to know objSample.dispose() is equal to objSample = null Indeed, can I get answer to such these questions from disassemblers? how? Thank you ...

Is There a Time at which to ignore IDisposable.Dispose?

Certainly we should call Dispose() on IDisposable objects as soon as we don't need them (which is often merely the scope of a "using" statement). If we don't take that precaution then bad things, from subtle to show-stopping, might happen. But what about "the last moment" before process termination? If your IDisposables have not been...