Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. COM
  4. How to delete a COM object - My Other Code

How to delete a COM object - My Other Code

Scheduled Pinned Locked Moved COM
comcsharpc++sysadminperformance
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AmitGG
    wrote on last edited by
    #1

    I have a C# (managed code) DLL and I am accessing this DLL's functions from C++ (unmanaged code) using COM. I create a COM object with CoCreateInstance function. Then I do work on this object. After that I call Release() function on this object. But after calling Release() function the object is not destroyed automatically. After calling Release function I called some more functions on this object and all those calls were successful. I also checked the return value of Release function call which is ZERO which shows the reference count of the object is ZERO and it should automatically destroy the object as soon as the reference count becomes ZERO. But in my case the object is not destroyed. Actually in my project work I have to create and destroy the COM object many times (1000-2000). So in each iteration the memory size is increasing and after some iteration it becomes more than 1 GB and fills all the page file space and the program hangs. Could Anybody suggest me how to delete the COM object. I have also given below the server side code which is in C#. The client side code which I am using is following : #import "ServerSideCode.tlb" named_guids high_method_prefix("") #include #include using namespace ServerSideCode; class Test { public: IEnterDetails *pPER1; IEnterDetails *pPER; IEnterAge *pAge; public: void Func1(); }; void Test::Func1() { pPER1 = NULL; HRESULT hr = CoInitialize(NULL); hr=CoCreateInstance(__uuidof(Manager), NULL, CLSCTX_INPROC_SERVER, __uuidof(IEnterDetails), reinterpret_cast(&pPER1)); pPER1->Print(); long a = pPER1->Release(); a = pPER1->Release(); a = pPER1->Release(); a = pPER1->Release(); // pPER1 = NULL; pPER1->EnterName(); pPER1->Print(); pPER1->QueryInterface(__uuidof(IEnterAge), reinterpret_cast(&pAge)); pAge->EnterAge(); pAge->Print(); a = pPER1->Release(); CoUninitialize(); } void main() { Test tt; tt.Func1(); } The C# code which was used to build the DLL (ServerSideCode.dll) is the following using System; namespace ServerSideCode { public interface IEnterDetails { void EnterName(); void EnterDesignation(); void EnterIncome1(); void EnterIncome2(); void Add(); void Print(); } public interface IEnterAge { void EnterAge(); void Print(); int Age {get; set;} } public class Person : IEnterDetails { private string Name = "DefaultName", Des = "DefaultDesignation"; private int i

    A 1 Reply Last reply
    0
    • A AmitGG

      I have a C# (managed code) DLL and I am accessing this DLL's functions from C++ (unmanaged code) using COM. I create a COM object with CoCreateInstance function. Then I do work on this object. After that I call Release() function on this object. But after calling Release() function the object is not destroyed automatically. After calling Release function I called some more functions on this object and all those calls were successful. I also checked the return value of Release function call which is ZERO which shows the reference count of the object is ZERO and it should automatically destroy the object as soon as the reference count becomes ZERO. But in my case the object is not destroyed. Actually in my project work I have to create and destroy the COM object many times (1000-2000). So in each iteration the memory size is increasing and after some iteration it becomes more than 1 GB and fills all the page file space and the program hangs. Could Anybody suggest me how to delete the COM object. I have also given below the server side code which is in C#. The client side code which I am using is following : #import "ServerSideCode.tlb" named_guids high_method_prefix("") #include #include using namespace ServerSideCode; class Test { public: IEnterDetails *pPER1; IEnterDetails *pPER; IEnterAge *pAge; public: void Func1(); }; void Test::Func1() { pPER1 = NULL; HRESULT hr = CoInitialize(NULL); hr=CoCreateInstance(__uuidof(Manager), NULL, CLSCTX_INPROC_SERVER, __uuidof(IEnterDetails), reinterpret_cast(&pPER1)); pPER1->Print(); long a = pPER1->Release(); a = pPER1->Release(); a = pPER1->Release(); a = pPER1->Release(); // pPER1 = NULL; pPER1->EnterName(); pPER1->Print(); pPER1->QueryInterface(__uuidof(IEnterAge), reinterpret_cast(&pAge)); pAge->EnterAge(); pAge->Print(); a = pPER1->Release(); CoUninitialize(); } void main() { Test tt; tt.Func1(); } The C# code which was used to build the DLL (ServerSideCode.dll) is the following using System; namespace ServerSideCode { public interface IEnterDetails { void EnterName(); void EnterDesignation(); void EnterIncome1(); void EnterIncome2(); void Add(); void Print(); } public interface IEnterAge { void EnterAge(); void Print(); int Age {get; set;} } public class Person : IEnterDetails { private string Name = "DefaultName", Des = "DefaultDesignation"; private int i

      A Offline
      A Offline
      AmitGG
      wrote on last edited by
      #2

      Please help me . :mad: :confused: :~ :(( :(( :(( :(( :((

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups