dispose

Do custom events need to be set to null when disposing an object?

Lets says we have 2 objects, Broadcaster and Listener. Broadcaster has an event called Broadcast to which Listener is subscribed. If Listener is disposed without unsubscribing from the Broadcast event it will be retained in memory because of the event delegate referencing it that Broadcaster contains. What I'm curious about is if Broad...

Need I remove controls after disposing them?

.NET 2 // dynamic textbox adding myTextBox = new TextBox(); this.Controls.Add(myTextBox); // ... some code, finally // dynamic textbox removing myTextBox.Dispose(); // this.Controls.Remove(myTextBox); ?? is this needed Little explanation Surely, if I Dispose a control I will not see it anymore, but anyway, will remain a "Nothing"...

C# - I know, I know, another question about Dispose (more related to design)!

Possible Duplicate: Should I Dispose() DataSet and DataTable? OP comment: I would like to say that the "Should I Dispose() DataSet and DataTable?" link isn't a possible solution. It's a good link, but this is more design related. Instead, ignore that the exposed property is a DataSet and replace it with something that should ...

Implement Dispose(bool) on a UserControl

How to implement the Dispose(boolean) at a UserControl... when the VS Designer already implemented it with a DebuggerNonUserCode attribute? Will my modifications on this method removed? (code from UserControl.Designer.vb) <System.Diagnostics.DebuggerNonUserCode()> _ Protected Overrides Sub Dispose(ByVal disposing As Boolean) ...

C# - Design-related dispose question (take two)

I asked a question earlier today, but I think I need to approach it in a different way (on top of that there was a "hang up" in regards to DataSet). Here's a class that encapsulates the creation of a Font (in other words, it is reading data from an xml file and is creating a font, at runtime, based on what it reads from that file): pub...

Adding and removing controls and memory usage in WindowsForm

I have a WindowsForm with a panel control which I use to display my UserControls. I add controls this way: private void AddControl(Control control) { panel.Controls.Clear(); control.Size = new Size(panel.Width - 1, panel.Height - 1); control.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles...

c# cannot access a disposed object

I am making an server/client application. I set server socket to listening, and set BeginAccept() method. And when I closed server socket (Socket.Close()) to turn off server, an exception thrown from BeginAccept() method's async callback method. I inspected exception, and I found the exception saying me this: Message "Cannot access a d...

How to override a Dispose method with diposedValue being Private?

Hello, I must add some Dispose code to a class that inherits from a class that already implements IDisposable so I tried to do an Override of the Dispose method but I have not available the disposedValue because it is declared as private. How can I add the new Dispose statements? Protected Overridable Sub Dispose(ByVal disposing As Bo...

I want my memory back! How can I truly dispose a control?

I have an application I am making that creates a large number of windows controls (buttons and labels etc). They are all being made dynamically through functions. The problem I'm having is, when I remove the controls and dispose them, they are not removed from memory. void loadALoadOfStuff() { while(tabControlToClear.Controls.Count ...

Using IDisposable To Unsubscribe an Event-- Do I need to Put Other Things Inside the Dispose?

I have the following class public class Presenter: IDisposable { public IView View {get;private set;} //snip other object reference, all managed public Presenter(IView view) { View=view; View.MouseUp += MouseUpEvent; } public void MouseUpEvent() { //do whatever you want to do on mouse up } public...

What is the accepted pattern of killing background tasks in a WinForms app

I got a .net WinForms application. I have a UserControl which gets instantiated based on user action - upon instantiation, it performs some time-consuming tasks on a background thread (using BackgroundWorker), while displaying the ajaxy spinning animation. The user can click away at anytime, then click back onto the user control (which...

unable to delete image after opening it in vb.net app

I have this code: Dim xx as image xx = image.fromfile(Fileloc) picturebox.image = xx And i can't delete the file even though I've loaded it into a picture box. If I add this line: xx.dispose the picture box becomes a big red X. I only want to delete the images when my application is closing (they are temp files). So shall I just...

Worker thread and Dipose()

Hi, I have some utility class with worker thread with simple exit condition. I use this class in my application. Worker thread is created and started in class constructor. class MyClass { Thread _thread; // unrelevant details are omitted void WorkerThreadRoutine { while(_running) { // do some useful background work here } } }...

How to dispose WCF services correctly?

My WCF service is IDisposable because it uses a ReadWriterLockSlim. When I dispose both of them in the following method: public void Dispose() { lockSlim.Dispose(); } Some of the public methods are still running (or accepting new connections, I don't know), and it fires exceptions because of the attempts of using disposed objects ...

SQL Server Physical Memory Grow After Execution of Commands

Dear GURUs I am running Server Application on Windows Server 2008 with SQL Server 2008, Now My scenario is as Given. I have implemented a custom Connection Pooling (why I did that its another long story). therefore I am not opening or closing connection on each request. Server Application executes more than thousands DBCommand in a m...

Microsoft not disposing of their own objects?

EDIT: Server is MOSS 2007 Enterprise, running SP1 and all patches up to, but not including, SP2. SP2 is coming soon. In one of my SharePoint apps, I am getting this warning & stacktrace over and over (with different GUIDS): since it's only one of my apps, I assume there's something in my project's code, but SPDisposeCheck returns cle...

C# .NET object disposal

Should be an easy one. Let's say I have the following code: void Method() { AnotherMethod(new MyClass()); } void AnotherMethod(MyClass obj) { Console.WriteLine(obj.ToString()); } If I call "Method()", what happens to the MyClass object that was created in the process? Does it still exist in the stack after the call, even thou...

What can cause a form not to close itself? (3.update) solved

I wonder just what can cause a form not to close. I have a big form, with several TabControls, DataGridViews and many DataBound-Controls, at least 10 BindingSources are involved. (Thats the point why I can't post my code here, sorry). Now, I have the problem, that somewhere in development (just refaktoring) the form stopped closing co...

How do I check if my object is properly disposed?

I wonder if there a "trick" that permits to know if the used objects in a portion o code has been properly(entirely) disposed, or, in other words don't creates memory leaks. Let's say I have a container of GDI objects (or other that I need to explicitly dispose) public class SuperPen { Pen _flatPen, _2DPen, _3DPen; public Sup...

WPF: How to dispose ImageBrush?

I'm using ImageBrush as a background of InkCanvas. I have to dispose the ImageBrush when deleting but the memory still raise up until the program throws an Exception (Out of Memory). I did use freeze Method and making the ImageBrush = null and giving it Empty Source but the memory still raising up. Have you found any solution to dispos...