473,394 Members | 1,703 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,394 software developers and data experts.

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 1884
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.Dispose 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.Dispose 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.Dispose 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.suppressfinalize().
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/
"RiteshDotNet" <Ri**********@discussions.microsoft.com> wrote in message
news:BF**********************************@microsof t.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
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...
11
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...
10
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...
16
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
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...
156
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...
4
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...
71
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...
44
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...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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.