Dispose question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I wrote a manage c++ wrapper classes that wraps an unmanaged c++ classes.
if my unmanaged c++ classes don't used any critical resources , do i still
need to make my managed c++ wrapper classes to implement IDisposable just
because they are wrapping an unmanage c++ class ?

Thanks.
 
Hi yaron!
I wrote a manage c++ wrapper classes that wraps an unmanaged c++ classes.
if my unmanaged c++ classes don't used any critical resources , do i still
need to make my managed c++ wrapper classes to implement IDisposable just
because they are wrapping an unmanage c++ class ?

If you do not need to free memory or any other stuff, you do not need to
implement IDisposable.

In general you can say: If every method/property in your wrapper class
always instanciate a new unmanaged-class then also frees it, you do not
need an IDisposable...

If you instanciate your unmanaged class only once (for example in the
managed constructor) you should implement IDisposable to free this
instance. I do not suggest to use the finilazier, because then you will
be called from a different thread (if at all) and some unmanaged classes
have some troubles with this...

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
Hi Jochen Kalmbach,

but is this is not the work of the GC to free the memory of my __gc wrapper
classes and the unmanage classes they are holding pointers to ?

Thanks.
 
Hi yaron!
but is this is not the work of the GC to free the memory of my __gc wrapper
classes and the unmanage classes they are holding pointers to ?

Yes. The GC will call your finilizer if GC think it should. But this
will be done from a different thread... and it also might never called
(for example at some circumstances at shutdown)...

It is better, if you provide IDisposable _and_ implement the
finalizer... so the user can either call Dispose or if the user forgets,
the finalizer will be called.

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
Back
Top