Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / July 2005

Tip: Looking for answers? Try searching our database.

Dispose question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
yaron - 03 Jul 2005 09:11 GMT
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.
Jochen Kalmbach [MVP] - 03 Jul 2005 10:11 GMT
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...

Signature

Greetings
  Jochen

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

yaron - 03 Jul 2005 10:58 GMT
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!
>
[quoted text clipped - 15 lines]
> be called from a different thread (if at all) and some unmanaged classes
> have some troubles with this...
Jochen Kalmbach [MVP] - 03 Jul 2005 11:47 GMT
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.

Signature

Greetings
  Jochen

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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.