- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我遇到了 WeakGlobalRef 指向垃圾收集对象的问题,当我尝试在此引用上调用 CallVoidMethod 时,这个应用程序崩溃了。为了解决这个问题,我执行以下操作:
jobject javaObject = pEnv->NewLocalRef(m_pJavaObject);
if (javaObject)
{
pEnv->CallVoidMethod(javaObject, method, object);
}
这仍然在 CallVoidMethod 崩溃,这样做是否有效,或者我是否也应该检查本地引用 IsSameObject
我得到的最后一件事,没有任何东西可以指向任何方法:
Crash reason: SIGSEGV
Crash address: 0xdead4321
Process uptime: not available
Thread 0 (crashed)
(...)
41 libart.so + 0xba7df
sp = 0xbeed2dc0 pc = 0xb4eca7e1
Found by: stack scanning
42 libxxx.so!_JNIEnv::CallVoidMethod(_jobject*, _jmethodID*, ...) [jni.h : 650 + 0x1]
sp = 0xbeed2dd8 pc = 0x9fabbeb9
Found by: stack scanning
最佳答案
should I also do check on local ref IsSameObject
The documentation提供答案:
it is recommended that a standard (strong) local or global reference to the same object be acquired using the JNI functions
NewLocalRef
orNewGlobalRef
, and that this strong reference be used to access the intended object. These functions will return NULL if the object has been freed, and otherwise will return a strong reference (which will prevent the object from being freed). The new reference should be explicitly deleted when immediate access to the object is no longer required, allowing the object to be freed.
如果对象已被释放,您将从 NewLocalRef
获得 NULL
,因此无需调用 IsSameObject
。
关于android - 来自 WeakGlobalRef 的 JNI LocalRef,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40019971/
我遇到了 WeakGlobalRef 指向垃圾收集对象的问题,当我尝试在此引用上调用 CallVoidMethod 时,这个应用程序崩溃了。为了解决这个问题,我执行以下操作: jobject java
我是一名优秀的程序员,十分优秀!