Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7028631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:26:06+00:00 2026-05-28T00:26:06+00:00

I’m currently looking into using C++/CLI to bridge the gap between managed C# and

  • 0

I’m currently looking into using C++/CLI to bridge the gap between managed C# and native, unmanaged C++ code. One particular issue I’m looking to resolve, is the conversion of data types that are different in C# and C++.

While reading up on the use of such a bridging approach and the performance implications involved, I wondered how Garbage Collection would work. Specifically, how the Garbage Collector would handle cleanup of objects created on either side, if they are referenced / destroyed on the ‘other side’.

So far, I’ve read various articles and forum questions on StackOverflow and MSDN, which has lead me to believe that the Garbage Collector should work across both types of code when running in the same process – i.e if an object was created in C# and passed to the C++/CLI bridge, it would not be collected until the references on both sides were no longer in use.

My question in this case, breaks down into three parts:

  1. Am I right in concluding that the Garbage Collector works across both portions of code (C# and C++/CLI) when running in the same process?
  2. In relation to 1: how does it work in such a circumstance (specifically in terms of cleaning up objects referenced by both code bases).
  3. Are there any suggestions on how to monitor the activity of the Garbage Collector – i.e. writing tests to check when Garbage Collection occurs; or a program that monitors the Garbage Collector itself.

I already have somewhat of an understanding of how the Garbage Collector works in general, so my questions here are specific to the following scenario:

Components

  • Assembly A – (written in C#)
  • Assembly B – (written in C++/CLI)

Program Execution

  1. Object O is created in Assembly A.
  2. Object O is passed into a function inside Assembly B.
  3. Reference to object O in Assembly A is released.
  4. Assembly B holds onto reference to object O.
  5. Execution ends (i.e. via program exit).
  6. Assembly B releases reference to object O.

Thanks in advance for any thoughts on this question. Let me know if further information is needed or if something is not clear enough.

EDIT

As per request, I have written a rough example of the scenario I’m trying to describe. The C# and C++/CLI code can be found on PasteBin.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:26:07+00:00Added an answer on May 28, 2026 at 12:26 am

    When the code is actually running, none of it will be C# or C++/CLI. All of it will be IL from the C# and C++/CLI and machine code from the native code you’re interoperating with.

    Hence you could re-write part of your question as:

    • Assembly A – (IL and we don’t know what it was written in)
    • Assembly B – (IL and we don’t know what it was written in)

    Of the managed objects, all of them will be garbage collected as per the same rules, unless you use a mechanism to prevent it (GC.KeepAlive). All of them could be moved in memory unless you pin them (because you’re passing addresses to unmanaged code.

    .NET Profiler will give you some information on garbage collection, as will the collection counts in performance monitor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm making a simple page using Google Maps API 3. My first. One marker
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.