Re: Managed class inherit from unmanaged class
- From: Cuong Tong <cuong.tong@xxxxxxxxx>
- Date: Sun, 9 Dec 2007 22:40:45 +0000 (UTC)
Hello Nicholas
Thanks for your help.
I should have explained myself a little bit better. Let me redraw the picture again. By unmanaged resource I meant native c++ classes.
Basically I have some existing native c++, now I am writing some c++/cli that inherits from those unmanaged classes.
I am just not so sure what would the garbage collector do with these kind of classes.
Regards,
Cuong Tong
By unmanaged class, I assume that you mean a class that is
imported through COM interop.
If you derive from this class, and an instance of this class is
GCed, then the runtime will take care of releasing the reference that
the runtime callable wrapper holds on the interface instance for the
COM object. Assuming that is the only reference that exists, when the
reference count is zero, the COM object will dispose of itself.
However, just letting instances of your class be GCed like that
isn't a good idea, since you are leaving an unmanaged resource hanging
around waiting to be GCed. You would have to pass instances of your
class to the static ReleaseComObject method on the Marshal class when
clients are done using it, to make sure that the unmanaged reference
is released ASAP when you are done with it.
"ttc" <cuong.tong@xxxxxxxxx> wrote in message
news:FA7863CA-C2B6-4021-ABC1-6C81424D4A01@xxxxxxxxxxxxxxxx
Hi All,
I have a managed class that inherits from an unmanged class. The
question is, if the object of the manged class get garbage collected,
will the memory be free automatically for me or only the bit that is
used by the managed code? What about the unmanaged bit?
Does anyone know of any article that discuss about this?
Any help is appreciated.
Cuong Tong
.
- Follow-Ups:
- Re: Managed class inherit from unmanaged class
- From: Nicholas Paldino [.NET/C# MVP]
- Re: Managed class inherit from unmanaged class
- References:
- Re: Managed class inherit from unmanaged class
- From: Nicholas Paldino [.NET/C# MVP]
- Re: Managed class inherit from unmanaged class
- Prev by Date: Re: Using Interface to dispose and null and object
- Next by Date: How attach to aspnet_wp under Vista?
- Previous by thread: Re: Managed class inherit from unmanaged class
- Next by thread: Re: Managed class inherit from unmanaged class
- Index(es):
Relevant Pages
|