Bug 3222 - GC does not release COM objects
Summary: GC does not release COM objects
Alias: None
Product: Runtime
Classification: Mono
Component: Interop ()
Version: unspecified
Hardware: PC Windows
: Low normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2012-02-04 04:03 UTC by trilog
Modified: 2017-07-11 22:10 UTC (History)
5 users (show)

Is this bug a regression?: ---
Last known good build:

Simple test program that verifies the bug. (2.01 KB, application/x-zip-compressed)
2012-02-04 04:03 UTC, trilog

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description trilog 2012-02-04 04:03:15 UTC
Created attachment 1316 [details]
Simple test program that verifies the bug.

When creating an unmanaged COM object and a managed proxy for that, GC does not release the proxy object. COM proxies are freed by GC but not released which results a memory leak in unmanaged side. The behavior is different from Microsoft's .NET runtime which releases COM proxies when GC collects. There is no difference if assembly is compiled with Mono's compilers or Microsoft's .NET compilers. However, assembly compiled with Mono and ran by Microsoft .NET the behavior is correct (COM proxies are released by GC). 

Mono runtime seems to release active COM proxies when runtime is cleaned up. So, it does not leak memory every time. Memory is leaked if GC collects, requested manually or automatically, before final runtime cleanup.
Comment 1 Rodrigo Kumpera 2012-08-30 14:17:40 UTC
This is a COM Interop issue.
Comment 2 Rodrigo Kumpera 2014-01-12 15:32:42 UTC
Hey John, this is your area, is this a problem mono currently have?
Comment 3 Rodrigo Kumpera 2017-07-11 22:10:56 UTC
This test depends on precise stack scanning, it won't work on mono.

Closing as we have tests for this that shows this working.