我有一个 C# WP 应用程序要使用的 WP C++ 运行时组件。
在 C++ 运行时组件中,我有
public interface class ICallback
{
public:
virtual void DoSomething();
};
public ref class WindowsPhoneRuntimeComponent sealed
{
public:
WindowsPhoneRuntimeComponent();
void SetCallback(ICallback ^callback);
IMap<Platform::String^, Platform::Object^>^ CreateDictionary();
};
在 C# 应用程序中,我
CallbackImp
有ICallback
. 然后我做
CallbackImp cb = new CallbackImp ();
WindowsPhoneRuntimeComponent com = new WindowsPhoneRuntimeComponent();
// Set callback
com.SetCallback(cb);
// Get dictionary
IDictionary<string, object> dict = com.CreateDictionary();
我有以下问题
- cb和com是托管对象。那么 C++/CX 对象在哪里呢?我听说cb和com指向一些 C++/CX 对象(它们驻留在本机堆上),对吗?
- 如果cb和com由 .NET GC 释放,那么 C++/CX 对象是如何释放的呢?
- 当我将cb传递给运行时组件时,cb属于托管堆还是本地堆?
- dict驻留在哪里?谁来释放它?