Some question about IntPtr in C# , it can automatic cleaning by GC?

243 Views Asked by At

I load a dll which writen in c++, in this dll ,C++ manages memory requests and releases, for example, the function: Init( ref IntPtr connectHandle) to request, Close(IntPtr connectHandle) to release; In my code:

class Test
{
   public IntPtr _connectHandle;
   public Init()
   {
        cPlusPlus(ref connectHandle);
   }
   public Close()
   {
       cPlusPlus(_connectHandle);
   }
   ~Test()
   {
       Close();
   }
}

There are two object Test a and Test b, b = a.Clone()--There Clone() is deep copy. And two question worry to me.

  1. When I don't use b, Is set b = null, but b had IntPtr Type, it can be released by GC?
  2. If can, GC will release the memory which requsted by c++;
0

There are 0 best solutions below