我有一个WP C++运行时组件,需要由C# WP应用程序使用。
在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#应用程序中,我有一个实现了ICallback
的CallbackImp
。然后我执行以下操作:
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对象(驻留在本地堆上),是吗?
- 如果.NET GC释放了cb和com,那么C++/CX对象如何释放?
- 当我将cb传递给运行时组件时,cb属于托管堆还是本地堆?
- dict位于何处?谁会释放它?