idisposable

Appropriate implementation of IDisposable with Silverlight?

I'm working on a Silverlight app using the MVVM pattern. My ViewModel currently consists of a property that represents a collection of Model Objects: public ObservableCollection<IndexEntry> IndexList { get; set; } it also has several methods that will populate that collection with data that comes back from a web...

What is the difference between managed and native resources when disposing? (.NET)

I was reading the MSDN article about how to implement IDisposable and I am uncertain about the difference between managed and native resources cited in the article. I have a class that must dispose 2 of its fields when it is disposed. Should I treat them as Managed (dispose only when disposing = true) or Native resources? ...

If a generic collection is instantiated to contain iDisposable items, do the items get disposed?

For example: Queue<System.Drawing.SolidBrush> brushQ = new Queue<System.Drawing.SolidBrush>(); ... brushQ.Clear(); If I don't explicitly dequeue each item and dispose of them individually, do the remaining items get disposed when calling Clear()? How about when the queue is garbage collected? Assuming the answer is "no", then what is...

Session containing items implementing IDisposable

In ASP.NET if items are left in the session state that Implement IDisposable but are never specifically removed and disposed by the application when the session expires will Dispose be called on the objects that any code in Dipose() will execute? ...

Should I call Close on HttpWebResponse, even if it's inside a using statement?

The question says it all, I have some code like, this code is used very heavily: using (HttpWebResponse response = _GetHttpWebResponse(requestURIString, msgBody, methodType, contentType, headers)) { //*** do something with it... //*** Call response.Close() ??? } The code works fine today, but the connections to the serv...

Can I stop C++/CLI from adding IDisposable to my ref class?

C++/CLI helpfully generates the IDisposable scaffolding for you when you implement a destructor on a ref class. Also, if you don't implement a destructor, but your class has a member variable which implements IDisposable, then IDisposable is again automatically implemented on your class. It's pretty helpful and much better than how IDisp...

Should I separate Dispose logic into a partial class file?

While refactoring some C# classes, I've run into classes that implement IDisposable. Without thinking, I have created partial class files for each class that implements IDisposable interface. E.g.) For Stamper.cs -> Stamper.cs + Stamper.Dispose.cs where Stamper.cs contains actual logic for stamping and Stamper.Dispose.cs that contains...

Proper use of the IDisposable interface

I know from reading the MSDN documentation that the "primary" use of the IDisposable interface is to clean up unmanaged resources http://msdn.microsoft.com/en-us/library/system.idisposable.aspx. To me, "unmanaged" means things like database connections, sockets, window handles, etc. But, I've seen code where the Dispose method is imple...

Need to implement a finalizer on a class that uses TcpClient?

I have a class (say MyClass) that uses (has as a private field) a TcpClient object. MyClass implements IDisposable calling TcpClient.Close in the Dispose method. My question is should MyClass also implement a finalizer to call Dispose(bool Disposing) to free the TcpClient’s unmanaged resources in case MyClass.Dispose is not called by t...

ServiceContainer, IoC, and disposable objects

I have a question, and I'm going to tag this subjective since that's what I think it evolves into, more of a discussion. I'm hoping for some good ideas or some thought-provokers. I apologize for the long-winded question but you need to know the context. The question is basically: How do you deal with concrete types in relation to IoC ...

Is it safe to dispose the Icon after calling Icon.ToBitmap()?

After calling System.Drawing.Icon.ToBitmap() to create an image, is it safe to dispose the original Icon? ...

How to manage IDisposable Objects that are cached?

I have an object that is expensive to create, which uses some unmanaged resources that must be explicitly freed when done with and so implement IDisposable(). I would like a cache for instance of these expensive resources so that the creation cost is minimized, but I am having trouble knowing how to deal with the disposal. If the met...

Should you implement IDisposable.Dispose() so that it never throws?

For the equivalent mechanism in C++ (the destructor), the advice is that it should usually not throw any exceptions. This is mainly because by doing so you might terminate your process, which is only very rarely a good strategy. In the equivalent scenario in .NET ... A first exception is thrown A finally block is executed as a result ...

What's the point of overriding Dispose(bool disposing) in .NET?

If I write a class in C# that implements IDisposable, why isn't is sufficient for me to simply implement public void Dispose(){ ... } to handle freeing any unmanaged resources? Is protected virtual void Dispose(bool disposing){ ... } always necessary, sometimes necessary, or something else altogether? ...

Identify IDisposable objects

Hi, i have to review a code made by some other person that has some memory leaks. Right now i'm searching the disposable objects to enclause them with the using statement and i would like to know if there is a quick way that tells you all the disposable objects declared in. I mean something like resharper or another visual studio plugin....

IDisposable GC.SuppressFinalize(this) location

I use a default IDisposable implementation template (pattern) for my code. snippet: public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool isDisposing) { if (!this.disposed) { if (isDisposing) { //cleanup managed resources } ...

Costs involved with C# destructors (aka: finalizers)?

The destructor should only release unmanaged resources that your object holds on to, and it should not reference other objects. If you have only managed references you do not need to (and should not) implement a destructor. You want this only for handling unmanaged resources. Because there is some cost to having a destructor, you ough...

Tracking undisposed Disposable objects

Is there a tool that can scan your code and determine which objects that implement IDisposable are not being disposed in a code base at compile time or runtime? I have possible areas in the code that are not disposing objects but it's hard to look back and see which objects require this in the first place. ...

How does the IDisposable interface work?

I understand that it is used to deallocate unmanaged resources, however, I am confused as to when Dispose is actually called. I know it is called at the end of a using block, but does it also get invoked when the object is garbage collected? ...

How can a ViewModel know when data in a service is updated?

In my application, I've got several ViewModels that have a single service (repository, DAO, whatever), let's call it the WidgetService, injected into them. Let's say that one of these ViewModels is a listing of all of a users widgets. Another could be the ViewModel for editing/creating a single one of these Widgets. The user can vie...