Groups | Blog | Home
all groups > dotnet compact framework > september 2007 >

dotnet compact framework : basic question...destructors confusion


Ilya Tumanov [MS]
9/12/2007 12:09:51 PM
There are no destructors, there are finalizers (as your code shows). The
difference is what destructor in C++ is always called before class is
destroyed and finalizers might never be called and even if they are called
you can never predict when that would happened. That is why you have to call
(or implement) Dispose() instead of using finalizers.



If your class uses native resources then you have to implement IDisposable
interface correctly and call it from finalizer with "false" as argument:



Protected Overrides Sub Finalize()
Dispose(false)

End Sub

That argument means "Do NOT touch any managed objects" because they might be
already collected.



If you don't use any native resources in your class then you don't need to
implement IDispossable and you don't need finalizer.



See this for more info:



http://weblogs.asp.net/cnagel/archive/2005/01/23/359037.aspx



--
Best regards,



Ilya



This posting is provided "AS IS" with no warranties, and confers no rights.



*** Want to find answers instantly? Here's how... ***

1. Go to
http://groups-beta.google.com/group/microsoft.public.dotnet.framework.compactframework?hl=en
2. Type your question in the text box near "Search this group" button.
3. Hit "Search this group" button.
4. Read answer(s).

[quoted text, click to view]

Simon Hart
9/12/2007 2:08:03 PM
I *always* implement IDisposable even if I am not using unmanaged resources
so that I can use the using statement in C# and the Dispose method will clean
up any managed or unmanaged (if any) resources.
--
Simon Hart
http://simonrhart.blogspot.com


[quoted text, click to view]
Mobileboy36
9/12/2007 3:06:59 PM
Public sub New()



End sub



How to write a destructor in VB.NET?



Protected Overrides Sub Finalize()

???

End Sub





Why you have to call class.dispose than in some cases.

When I implement Finialize, do I have to implement Dispose too?







AddThis Social Bookmark Button