test_map.cpp
#include <map>
static std::map<long, EditCallback *> callbackMap;
/**
* 編輯模塊監(jiān)聽
*/
void setCallback(long pEngine, EditCallback *editCallback) {
callbackMap[pEngine] = editCallback;
}
void deleteCallback(long pEngine) {
if (callbackMap.count(pEngine) == 0) {
return;
}
int attach;
JNIEnv *env = GetAttachEnv(&attach);
if (env != nullptr) {
//銷毀java層監(jiān)聽對象
if (callbackMap[pEngine]->objCallback) {
env->DeleteGlobalRef(callbackMap[pEngine]->objCallback);
callbackMap[pEngine]->objCallback = nullptr;
}
}
if (attach) {
DetachEnv();
}
auto it = callbackMap.find(pEngine);
if (it != callbackMap.end()){
EditCallback* callback = it->second;
callbackMap.erase(pEngine);
delete callback;
callback = nullptr;
}
LOGE("delete EditCallbackMap. count:%d", callbackMap.size());
}