J
Joe
I am looking for the quintessential blueprint for how a
C++ like destructor should be implemented in C#. I see
all kinds of articles in print and on the web, but I see
lots of discrepencies. For example ...
C# Essentials (O'Reilly) - "Finalizers are class-only
methods". Not sure what "class-only method" means in this
context, but ususally I would assume that to mean it is
static and would only be called once for the life of the
program, and not once for every object of that class. Am
I reading this correctly? Is it just plain wrong? Will
the Finalize method be called once for every object?
Can an object's destructor/finalizer be called explicitly
by your code? Programming C# (O'Reilly) says no on page
80. Yet on MS site
(http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/dncscol/html/deepc10192000.asp?
frame=true) they say yes, search for "One simple solution
is to make the finalizer calls explicit" on that page.
So, lets assume I have a handle to an unmanaged resource
(intentionally vague), where exactly should I put my code
to free/close the handle? In the Finalize() or Dispose()?
As you can see, I have a poor understanding of the proper
way to do this. I have read lots of articles, but cannot
find any that actually look correct to me.
Thanks.
C++ like destructor should be implemented in C#. I see
all kinds of articles in print and on the web, but I see
lots of discrepencies. For example ...
C# Essentials (O'Reilly) - "Finalizers are class-only
methods". Not sure what "class-only method" means in this
context, but ususally I would assume that to mean it is
static and would only be called once for the life of the
program, and not once for every object of that class. Am
I reading this correctly? Is it just plain wrong? Will
the Finalize method be called once for every object?
Can an object's destructor/finalizer be called explicitly
by your code? Programming C# (O'Reilly) says no on page
80. Yet on MS site
(http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/dncscol/html/deepc10192000.asp?
frame=true) they say yes, search for "One simple solution
is to make the finalizer calls explicit" on that page.
So, lets assume I have a handle to an unmanaged resource
(intentionally vague), where exactly should I put my code
to free/close the handle? In the Finalize() or Dispose()?
As you can see, I have a poor understanding of the proper
way to do this. I have read lots of articles, but cannot
find any that actually look correct to me.
Thanks.