By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,682 Members | 1,999 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,682 IT Pros & Developers. It's quick & easy.

netFramwor and Dispose

P: n/a
..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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a


"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

P: n/a
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

P: n/a

--------------------
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 discussion thread is closed

Replies have been disabled for this discussion.