473,785 Members | 2,396 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

netFramwor and Dispose

..net Frame work
1. Dispose Method what it does ?
A. who its call / when it calls ?
B. Is it fire automatically ?
c. When dispose method is call what it does ?
D. Release a Object from memory or release refrence from memory ?
E. If it release object from memory then what GC does ?
2. Which class can have dispose method ?
class which is member of IDispose Inteface
3. Where we should use abstract / Interface ?
Jul 21 '05 #1
4 1934
1. Dispose Method what it does ?
It is a member of the IDisposable interface and it used to free
unmanaged resources (windows handles, files, ...)

A. who its call / when it calls ?
It is called explicitly by the users of the class that implements it. A
call to the Dispose method it is propagated to all the parent types of
this class.

B. Is it fire automatically ?
It can also called by the runtime inside a finalizer method

c. When dispose method is call what it does ?
It is implementation dependent. If you develop a class that uses
unmanaged resources (eg, handles), you should free that resources
inside the IDisposable.Dis pose method (eg. calling CloseHandle()).

D. Release a Object from memory or release refrence from memory ?
Releases an (unmanaged) object from memory at specific time

E. If it release object from memory then what GC does ?
GC frees unreferenced managed objects. GC has no knowledge of
unmanaged resources

2. Which class can have dispose method ?
class which is member of IDispose Inteface
Classes that create unmanaged resources should implement IDisposable
interface.

Jul 21 '05 #2


"Woody" wrote:
1. Dispose Method what it does ?
It is a member of the IDisposable interface and it used to free
unmanaged resources (windows handles, files, ...)

A. who its call / when it calls ?
It is called explicitly by the users of the class that implements it. A
call to the Dispose method it is propagated to all the parent types of
this class.

B. Is it fire automatically ?
It can also called by the runtime inside a finalizer method

c. When dispose method is call what it does ?
It is implementation dependent. If you develop a class that uses
unmanaged resources (eg, handles), you should free that resources
inside the IDisposable.Dis pose method (eg. calling CloseHandle()).

D. Release a Object from memory or release refrence from memory ?
Releases an (unmanaged) object from memory at specific time

E. If it release object from memory then what GC does ?
GC frees unreferenced managed objects. GC has no knowledge of
unmanaged resources

2. Which class can have dispose method ?
class which is member of IDispose Inteface
Classes that create unmanaged resources should implement IDisposable
interface.

Great,
Thanks

"Woody" wrote:
1. Dispose Method what it does ?
It is a member of the IDisposable interface and it used to free
unmanaged resources (windows handles, files, ...)
Here what do u mean of unmanage resources ?
bcoz if we are using C# in that case we are implicitly using managecode
,I think in that case we wont required dispose method bcoz GC will take care
of these things.
Yes we can also use unmanage code in C# , but for that we need to
explicitly compile these class as in unsafe mode , I think in that case
only dispose method will work ?



A. who its call / when it calls ?
It is called explicitly by the users of the class that implements it. A
call to the Dispose method it is propagated to all the parent types of
this class.
c. When dispose method is call what it does ? It is implementation dependent. If you develop a class that uses
unmanaged resources (eg, handles), you should free that resources
inside the IDisposable.Dis pose method (eg. calling CloseHandle()).


In (A .) You are saying that its called explicitly ? if it call explicitly
how we can call
how we can call finalize method ?
Is there any finalize method , I think finalize is part of
gc.suppressfina lize().
What happend when we call object=null ?
1.1 It will also release resources ?
1.2 It will called finalize / dispose method ?

2.1 What is diffrence between finalize and dispose method ?
2.2 who will call to whome ?
2.3 finalize call dispose / dispose call finalize ?
2.4 how it will called (finalize/dispose) ?

Thanks in advance


Jul 21 '05 #3
Check out the articles reference in this blog post. They should answer all
your questions.

http://msmvps.com/windsor/archive/2004/05/18/6706.aspx

--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
http://msmvps.com/windsor/
"RiteshDotN et" <Ri**********@d iscussions.micr osoft.com> wrote in message
news:BF******** *************** ***********@mic rosoft.com...
.net Frame work
1. Dispose Method what it does ?
A. who its call / when it calls ?
B. Is it fire automatically ?
c. When dispose method is call what it does ?
D. Release a Object from memory or release refrence from memory ?
E. If it release object from memory then what GC does ?
2. Which class can have dispose method ?
class which is member of IDispose Inteface
3. Where we should use abstract / Interface ?

Jul 21 '05 #4

--------------------
Here what do u mean of unmanage resources ?
bcoz if we are using C# in that case we are implicitly using managecode
,I think in that case we wont required dispose method bcoz GC will take care
of these things.
Yes we can also use unmanage code in C# , but for that we need to
explicitly compile these class as in unsafe mode , I think in that case
only dispose method will work ?
By unmanaged resources, we mean file handles, bitmaps, database collections, essentially any resource outside the scope of the runtime. What you're describing is unsafe
code, which is a different concept.

In (A .) You are saying that its called explicitly ?
Yes, Dispose is called explicitly by the user code.
how we can call finalize method ?
You can't. The finalizer is called by the GC at some undetermined time after the object has been collected.
What happend when we call object=null ?
1.1 It will also release resources ?
1.2 It will called finalize / dispose method ?
Setting an object to null does not do anything, except remove the reference to the object in memory. See http://weblogs.asp.net/clyon/archive...01/273144.aspx.
2.1 What is diffrence between finalize and dispose method ?
2.2 who will call to whome ?
2.3 finalize call dispose / dispose call finalize ?
2.4 how it will called (finalize/dispose) ?


For answers to these questions, please see the Dispose Pattern Guidelines:
http://msdn.microsoft.com/library/de...izedispose.asp

Further reading regarding the use of Dispose:
http://weblogs.asp.net/clyon/archive...21/232445.aspx
http://weblogs.asp.net/clyon/archive...23/233464.aspx
Hope that helps!
-Chris

--

This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they originated.

Jul 21 '05 #5

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

Similar topics

3
6076
by: faktujaa | last post by:
Hi All, A small confusion. I have defined a connection class that has System.Data.IDbConnection as a member variable and implements IDisposable interface. I have implemented Dispose method to call Dispose method of IDbConnection. This Dispose method is called from a destructor. In the dispose method, i also call GC.SuppressFinalize(this) so as to avoid finalizer. All this was OK untill i came across one article that says - not to call...
11
5312
by: Ken Durden | last post by:
I am in search of a comprehensive methodology of using these two object cleanup approaches to get rid of a number of bugs, unpleasantries, and cleanup-ordering issues we currently have in our 4-month old C#/MC++ .NET project project. I'd like to thank in advance anyone who takes the time to read and/or respond to this message. At a couple points, it may seem like a rant against C# / .NET, but we are pretty firmly stuck with this approach...
10
18546
by: Henrik Dahl | last post by:
Hello! After I've finished using an instance of the SqlCommand class, should I then invoke Dispose() on the instance. I suppose so, as there is a Dispose method, but what does it actually release? I would basically prefer to skip invoking Dispose() as this will free me from determining when the usage actually has finished.
16
4263
by: Daniel Mori | last post by:
If an object implements the IDisposable interface (regardless if its a framework object or a user object), should I always dispose of that object out of principle?
3
2078
by: Maxim | last post by:
Hi! According to documenation, if we need to release some umanaged resources manually, we need to implement IDisposable interface with single Dispose method. I am just wondering, what will happen if I just create my own Dispose (or any other name) mehtod, without implementing the IDisposable interface. In all the examples, which I found, this Dispose method called from my user code (not by GC). What do I miss? Thanks.
156
5905
by: Dennis | last post by:
Ok, I'm trying to dispose of every object that I create that has a dispose method based on advice from this newsgroup. However, I'm not sure how to dispose of the following object that was created inside a method call. dim myvar as new object1 object1.dosomethingmethod(new object2) Note that object 2 has a dispose method but how do I dispose of it unless I do the following:
4
271
by: RiteshDotNet | last post by:
..net Frame work 1. Dispose Method what it does ? A. who its call / when it calls ? B. Is it fire automatically ? c. When dispose method is call what it does ? D. Release a Object from memory or release refrence from memory ? E. If it release object from memory then what GC does ? 2. Which class can have dispose method ? class which is member of IDispose Inteface 3. Where we should use abstract / Interface ?
71
10761
by: active | last post by:
In the main program I check to see if a certain form has been disposed. Does it make sense in that form's FormClosed event to do: Me.Dispose to make sure it is disposed the next time I check. Or is that automatic? Thanks
44
8274
by: Smokey Grindle | last post by:
I have a list box on my form, but I need to databind it to a data table that is a private member of the form's class... so I basically have Public Class MyForm priate m_MyTable as new datatable End Class now where would I properly dispose of this? In the finalize method? I am loading the data for the table in a subroutine that is executed at form load, of course all the commands tied to it are wrapped in using blocks, but
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9481
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10341
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10095
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9954
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7502
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.