Re: Problem with C# not calling MC++ destrcutor
- From: Jeremy Chaney <j*c@xxxxxxxxxxxxxx>
- Date: Fri, 02 Feb 2007 10:41:34 -0800
Lebesgue wrote:
I'm pretty surprised to hear that it is possible for my Finalizers to
not be called at shutdown. If I am being required to manually free up my
resources, what is the point of GC?
GC is here to clean up unreferenced _memory_. You should deal with other
(unmanaged) resources using the dispose pattern in C#. There has been a long
thread recently (named C++/CLI is the way to go) where a reference counted
model for disposing unused resources in C# has been proposed.
Can you show us your finalizers? My guess is you are trying to use them the
way they were not meant to be.
I think I'm sinking in over my head here... :) When you say Finalizers,
do you mean my "~MyClass" method?
Here it is:
~MyCSharpClass()
{
foreach (KeyValuePair<Char, MyManagedCPPClass> kvp in m_MyMap)
{
kvp.Value.Dispose();
}
m_myotherManagedCPPClass.Dispose();
}
The need for this destructor (I'm going to call it that until someone
tells me what to call it in C#) is surprising to me. The objects that I
have to call Dispose on are both Managed C++ objects. Shouldn't they
have their destructors called when "~MyCSharpClass" is called? . Before
I added the calls to Dispose, "~MyCSharpClass" was always called, but
the destructors for my Managed C++ objects were not. (I fixed this with
the addition of Dispose).
Thanks,
--Jeremy
.
- Follow-Ups:
- Re: Problem with C# not calling MC++ destrcutor
- From: Lebesgue
- Re: Problem with C# not calling MC++ destrcutor
- From: Göran Andersson
- Re: Problem with C# not calling MC++ destrcutor
- References:
- Problem with C# not calling MC++ destrcutor
- From: Jeremy Chaney
- Re: Problem with C# not calling MC++ destrcutor
- From: Göran Andersson
- Re: Problem with C# not calling MC++ destrcutor
- From: Jeremy Chaney
- Re: Problem with C# not calling MC++ destrcutor
- From: Lebesgue
- Problem with C# not calling MC++ destrcutor
- Prev by Date: Re: How to audit application actions.
- Next by Date: Re: Casting an enum, skips one for no reason?
- Previous by thread: Re: Problem with C# not calling MC++ destrcutor
- Next by thread: Re: Problem with C# not calling MC++ destrcutor
- Index(es):
Relevant Pages
|
Loading