title: Circular Dependency when calling destructors
body: <p>I have the following architecture, and because of the inheritance, it is causing circular dependency when <code>destructors</code> are being called on the classes.</p>
  
  <pre><code>namespace IntOp
  {
      ref class PwItem;
      ref class PwTag;
  
  public ref class PwItem
  {
      public:
        PwItem(void* arg1, &lt;sometype&gt;arg2, unsigned __int64 arg3);
        {
            // some constructor work
        }
        virtual ~PwItem(){};
        static PwItem^ PwItem::CreateItem(void* arg1, &lt;sometype&gt;arg2, unsigned __int64 arg3) 
       {
          if(arg2 is of type PTag)
          {  //  PTag = gcnew PwTag(arg1, arg2, arg3);
             //  return PTag;
           return gcnew PwTag(arg1, arg2, arg3);
          }
          else if(arg2 is of type PFile)
          {    //PFile = gcnew PwTag(arg1, arg2, arg3);
              // return PFile;
           return gcnew PwFile(arg1, arg2, arg3);
          }
          return gcnew PwItem(arg1, arg2, arg3);
       }
  
     private : 
  
       //PwTag^ PTag;
     //  PwFile^ PFile;  //Another type with PwItem as Base constructor
   }
  
  
  public ref class PwTag : PwItem
  {
      public:
      PwTag(void* arg1, &lt;sometype&gt;arg2, unsigned __int64 arg3) : PwItem (void* arg1, &lt;sometype&gt;arg2, unsigned __int64 arg3) {};
     virtual ~PwTag();
  }}
  </code></pre>
  
  <p>So here, when I want to call a delete on <code>PwItem</code>, so it releases the instantiation of <code>PwItem</code>, then because of the inheritance, <code>PwTag</code> calls the <code>destructor</code> on <code>PwItem</code>, and the whole thing keeps repeating itself.</p>
  
  <p>How can this issue be resolved? The <code>destructor</code> really needs to be called to release some stuff which is there in the class object.</p>
  
  <p><strong>EDIT : Added calling code</strong></p>
  
  <pre><code>myServer srv = new myServer();
  srv.connect();
  while(true)
  {
      PwItem ^item = srv.GetItem(&lt;some string&gt;); //This will invoke the GetItem function, which will call createItem()
      System.Threading.Thread.Sleep(200);
  }
  </code></pre>
  
  <p><strong>Actual GetItem() function</strong></p>
  
  <pre><code>PwItem^ myServer::GetItem(&lt;some string&gt;)
  {
  
      // do some work, nothing new being instantiated etc. just arguments 1, 2 and 3, which do not cause leaks
      return gcnew PwItem::CreateItem(arg1, arg2, arg3);
     // Tried instantiating a PwItem pi; return pi.CreateItem(arg1, arg2, arg3); as well. No luck
     // Bypassed PwItem entirely, and based on arg2, called return gcnew PwTag(arg1, arg2, arg3); as well, no luck
     // Tried PwItem pi, ^tempPwItem; tempPwItem = pi.CreateItem(arg1, arg2, arg3); return tempPwItem; No luck
  }
  </code></pre>