C# 免费IntPtr到IntPtr

C# 免费IntPtr到IntPtr,c#,intptr,unmanaged-memory,C#,Intptr,Unmanaged Memory,我有一个名为“家长”的班: Class Parent { String Name; IntPtr Childs; // this pointer actual type is 'Array of Child' and it was storred as unmanned array int ChildsCount;// count of 'array of Child' } 班级儿童: Class Child { String Name; IntPtr

我有一个名为“家长”的班:

Class Parent
{
    String Name;
    IntPtr Childs; // this pointer actual type is 'Array of Child' and it was storred as unmanned array
    int ChildsCount;// count of 'array of Child'
}
班级儿童:

Class Child
{
    String Name;
    IntPtr Photo; //Byte Array
}
所有数据都没有管理

现在在主程序的某个地方,我有一个
IntPtr
,它指向一个
父级

如果我尝试使用
Marshal.FreeHGlobal
释放此父级,则不会释放子级的真实数据

问题是:
如何在不编写逐步释放代码的情况下挖掘并自动释放数据?

为什么要使用非托管数据?包装问题。。我正在调用C++本地库,并在两个方向传递一些数据。没有圣诞老人。McSal.FrutHGLULL()实际上正确地破坏C++对象的可能性已经很低,它不知道C++析构函数的缺点。或者它会使用正确的堆,尽管当用VS2012或更高的代码编译C++代码时,情况是好的。但是精灵要求你摧毁每个单独的对象,就像C++程序那样。在C++代码中导出一个正确执行它的函数是非常值得推荐的。“强烈建议在C++代码中导出一个函数,它是正确的”,当然,这个函数正在破坏C++中创建的内容,而且我还要求破坏C语言中创建的未被发送的内存并发送给C++。