Skip to content

Conversation

Sergey-Vlasov
Copy link
Contributor

No description provided.

Sergey-Vlasov and others added 23 commits September 6, 2025 16:36
…time registrations out of Integration.NativeAOT.
Implemented NativeWindow using Win32 API
Implemented minimal LogDisplay using Win32 API, removed WindowsForms dependency
Added a RibbonController to ExcelDna.TestAOT project.
@Sergey-Vlasov Sergey-Vlasov requested a review from govert October 4, 2025 09:18

// Marshal to .NET, then call .Application
object obj = ComInterop.Util.TypeAdapter.GetObject(pUnk);
Marshal.Release(pUnk);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can we skip the Release here? It seems we end up calling Marshal.GetObjectForIUnknown which increments the reference count.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand,

The reference count will be decremented when the runtime performs garbage collection on the managed object that represents the COM object.

https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.marshal.getobjectforiunknown?view=net-9.0#remarks

In our case it will be decremented on line 510

                finally
                {
                    ComInterop.Util.TypeAdapter.ReleaseObject(obj);
                }

Calling Marshal.Release(pUnk) manually will over decrement the reference count.

@govert govert merged commit 90dc01c into master Oct 10, 2025
@govert govert deleted the NativeAOT branch October 10, 2025 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants