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 / .NET Framework / CLR / September 2003

Tip: Looking for answers? Try searching our database.

Memory leaks with unamaneged com objects

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Calm Interop - 11 Sep 2003 07:07 GMT
Hi,

I am getting a strange scenario where I am using RCWs for
CDO and ADO in my managed classes. When the managed
objects get destructed, it seems the referenced unmanaged
resources are stacking up in memory for ever.

Does'nt GC take of those too? Please note that I am using
these unmanaged object references in method level in
managed classes, but not at class level.

I have tried Marshal.ReleaseComObject method to
explicitly detroy the memory trace of the com object, but
there is no improvement noticed in memory usage by CPU,
and getting higher every minute.

Please let me know how to dispose unmanaged objects at
method level ? (The exact and right way indeed.)

Regards
Tom
Michael Green - 16 Sep 2003 01:08 GMT
Tom,

Unmanaged objects are not garbage collected. The garbage collector has no
knowledge of anything that is unmanaged. Your managed wrappers will get
garbage collected, but not the objects they reference. You will need to
explicitly release the unmanaged objects for them to get cleaned up. You
should be able to do this by calling IUnknown::Release on them.

I hope this is helpful,

Thanks,

Michael Green
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only.
David Browne - 16 Sep 2003 23:38 GMT
> Tom,
>
[quoted text clipped - 3 lines]
> explicitly release the unmanaged objects for them to get cleaned up. You
> should be able to do this by calling IUnknown::Release on them.

Actually, not so.  COM interop isn't _that_ broken.

After the Runtime Callable Wrapper for the COM object is garbage collected,
it's finalizer will decrement the reference count on the COM interface.  The
COM object will normally be destroyed at that point.

This may be a long time after you wanted the object to be destroyed, so you
can call

Marshal.ReleaseComObject()

To destroy the com object before you let the RCW go out of scope.

David

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.