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

  • SEARCH
  • Home
  • 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 3597240
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:05:34+00:00 2026-05-18T20:05:34+00:00

I’ve read the documentation for Marshal.GetIUnknownForObject and it says: Always use Marshal.Release to decrement

  • 0

I’ve read the documentation for Marshal.GetIUnknownForObject and it says:

Always use Marshal.Release to decrement the reference count once you have finished with the pointer.

I wrote a test solution with a COM object which I use via .NET and I see that when working with the wrapper to my COM object neither Marshal.GetIUnknownForObject nor Marshal.Release cause the AddRef or Release methods of my COM object to be called.

What’s up with that?

  • 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-18T20:05:34+00:00Added an answer on May 18, 2026 at 8:05 pm

    Wait a minute, I think I’ve got it. You are making a COM object, then you are making a runtime callable wrapper around that COM object, and then you’re asking the runtime callable wrapper for its punk, and then you’re wondering why calling release on that punk doesn’t call your Release? Does that sum up your question?

    If so, you might have mentioned all those details in the question rather than making us guess.

    Well, why do you suppose it would it call your Release? it’s going to call the Release of the runtime callable wrapper. The wrapper wraps your object; that’s why its called a wrapper. The runtime callable wrapper doesn’t need to addref and release your object every time it is addref’d and released! Why would it? It needs to keep your object alive and it already has a ref on your object; that is sufficient to keep the wrapped object alive. Why do unnecessary work?

    When you just have a runtime callable wrapper around a COM object you should reasonably expect to that the ref count on the object is unchanging for the entire lifetime of the object. The runtime takes a ref once, and when the RCW is garbage collected for the last time or released in some other manner, it releases that ref and the object deletes itself.

    Think about it like this. Suppose you said:

    foo->bar = blah;
    blah->AddRef();
    

    blah gets addref’d because foo->bar has a reference to it. Now you say:

    abc->def = foo;
    foo->AddRef();
    

    That adds a ref to foo. Does it add a ref to blah? Of course not. Why would it? foo has a ref to blah; the fact that foo is being kept alive by abc is irrelevant to blah.

    Same thing here. You have:

    wrapper = new RCW();
    wrapper->wrapped = yourobject;
    yourobject->AddRef();
    

    That adds a ref to yourobject. Now if you have

    wrapper->QI(IUnknown, &punk)
    

    that doesn’t give you the punk to the underlying object, it gives you the punk of the wrapper. If you say

    punk->AddRef();
    

    that doesn’t addref the underlying object, it addrefs the wrapper.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
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.