Top "Dispose" questions

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources

Should I always disconnect event handlers in the Dispose method?

I'm working in C# and my workplace has some code standards. One of them is that each event handler we …

c# .net events event-handling dispose
Dispose vs Dispose(bool)

I am confused about dispose. I am trying to get my code disposing resources correctly. So I have been setting …

c# dispose
What's the purpose of the components IContainer generated by the Winforms designer?

When you create a new form in Visual Studio, the designer generates the following code in the .Designer.cs file: /// &…

c# winforms dispose designer
Java Disposable pattern

C# supports disposable pattern for deterministic garbage collection using the dispose pattern. Is there such pattern for java? Java 7 has …

java garbage-collection dispose
How to dispose asynchronously?

Let's say I have a class that implements the IDisposable interface. Something like this: MyClass uses some unmanaged resources, hence …

c# asynchronous dispose
How to abort socket's BeginReceive()?

Naturally, BeginReceive() will never end if there's no data. MSDN suggests that calling Close() would abort BeginReceive(). However, calling Close() …

c# sockets asynchronous dispose
Do I need to consider disposing of any IEnumerable<T> I use?

It's recently been pointed out to me that various Linq extension methods (such as Where, Select, etc) return an IEnumerable&…

c# linq ienumerable dispose
Does "using" statement always dispose the object?

Does the using statement always dispose the object, even if there is a return or an exception is thrown inside …

c# dispose using using-statement
Returning value from JDialog; dispose(), setVisible(false) - example

I know, that this question appears quite frequently in SO like here: but I would like to present some very …

java swing dispose jdialog
Does calling Clear disposes the items also?

Many times there is a clear method, that removes all the items from the collections, are these items disposed also. …

c# .net collections dispose