473,395 Members | 1,656 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

What is the difference between Managed and Unmanaged resources in regards to IDisposable

Hi,
I'm implementing the Idisposable pattern and am wondering what the
difference it between managed, and unmanaged resources?

http://msdn2.microsoft.com/en-us/library/fs2xkftw.aspx

in the code snippet where it's overloading the Dispose method it
disposes of managed and unmanaged resources if disposing == true, and
only unmanaged resources if disposing is false. I'm not sure I
completely understand. Thank you in advance.

Jun 13 '06 #1
3 3279
Is a managed resource an object that has it's own dispose method, and
an unmanged resource one that you have to clean up, for example a
socket would be an unmanged resource as even though it's an object, it
has no dispose method, so you have to explicitly shutdown the socket,
close the socket and then null it out. Is this right?

Jun 13 '06 #2
Examples of unmanaged resources include operating system handles, file
handles, memory allocated by a direct call to a Win32 API, etc.
Unmanaged resources usually come into play when you use the interop
features provided by the framework.

The pattern dictates that disposing == true when called from the public
Dispose method. That means you (the developer) have chosen to
deterministicly dispose the object either directly by calling Dispose
or indirectly by using on of the C# constructs that automatically
generates the call to Dispose. If disposing == false then that means
the object is being disposed by the GC through the Finalize
(destructor) method.

The reason the pattern has two separate branches is because managed
resources cannot be touched when disposing == false since the GC may
have already disposed them.

Brian

DaTurk wrote:
Hi,
I'm implementing the Idisposable pattern and am wondering what the
difference it between managed, and unmanaged resources?

http://msdn2.microsoft.com/en-us/library/fs2xkftw.aspx

in the code snippet where it's overloading the Dispose method it
disposes of managed and unmanaged resources if disposing == true, and
only unmanaged resources if disposing is false. I'm not sure I
completely understand. Thank you in advance.


Jun 13 '06 #3
Thanks, that's what I figured. I appreciate the response.

Jun 14 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Billy Porter | last post by:
Greetings, I got a class that wraps the System.Data.SqlClient.SqlConnection class (no COM interaction). I'm not sure if I'm supposed to implement the IDisposable pattern for this wrapper or not....
4
by: Rachel Suddeth | last post by:
What is the difference between a managed/unmanaged resource, and how do you tell which is which? I'm trying to understand how to write some Dispose() methods, and we are supposed to put code that...
3
by: mirek | last post by:
Hi, I've got problem building managed class library to wrap unmanaged code. I created managed class library using standard patten: #include "../Unmanaged/Class1.h" //Class1 unmanaged ...
10
by: **Developer** | last post by:
What should I Dispose. For example, in the following what should I Dispose and what happens if I don't? Thanks Dim PS As New PrinterSettings PS.PrinterName =...
9
by: CMirandaman | last post by:
Perhaps someone can help me understand this. I'm trying to understand what the IDisposable interface actually does because as far as I can tell it seems to be just garnish on the plate. If I...
2
by: George Shui | last post by:
I use webBrowser to open a Word document, when I use this.webBrowser.dispose(), the WinWord Process end. while I use this.webBrowser = null, GC.Collect() , the WinWord Process still alive. I...
3
by: Mark | last post by:
If your class implements IDisposable, I was told that this increases the speed with which your class is garbage collected. Is this true? And if so, how much "time" does it save? Assume that we...
8
by: Varangian | last post by:
Hello, was wondering of how to dispose of managed resources? or referencing every member of a class to null will release resources...? http://www.marcclifton.com/tabid/79/Default.aspx...
66
by: John | last post by:
Hi What are the advantages actually achieved of managed code? I am not talking of theory but in reality. Thanks Regards
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.