当前位置: 代码迷 >> VC >> C++/CLI 内 delete 释放内存的有关问题
  详细解决方案

C++/CLI 内 delete 释放内存的有关问题

热度:7495   发布时间:2013-02-25 00:00:00.0
C++/CLI 内 delete 释放内存的问题.
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是释放非托管
  相关解决方案