我在一个C++/CLI项目中将托管的System.Action转换为非托管的std::function;在使用回调后,我需要释放给定的IntPtr吗,或者这是不必要的?
void MyClass::Execute(System::Action^ callback)
{
IntPtr callbackPtr = Marshal::GetFunctionPointerForDelegate(callback);
std::function<void (void)> nativeCallback = static_cast<void (__stdcall *) (void)>(callbackPtr.ToPointer());
m_nativeObject->Execute(wrappedCallback);
// should I release callbackPtr here?
}