- C/C++ code
using namespace System;public ref struct APP{ String^ TheString; APP(String^ inString) { TheString = inString; }};public ref class BPP{public: property APP^ TheAPP;public: BPP(APP^ inAPP) { TheAPP = inAPP; }};public ref class CPP{public: property APP^ TheAPP;public: CPP(APP^ inAPP) { TheAPP = inAPP; }};int main(){ APP^ app = gcnew APP("Weird."); CPP^ cpp = gcnew CPP(app); delete cpp; Console::WriteLine(cpp->TheAPP->TheString); Console::Read(); return 0;}
这代码编译通过, 运行起来输出为: Weird.
很费解, 求解释.
------解决方案--------------------------------------------------------
托管内存你是直接管不了的
------解决方案--------------------------------------------------------
dispose是释放非托管