如何解决 DeadObjectException 问题?
我已经成功完成了一个Android项目的实现,并开始测试该应用程序是否存在内存泄漏。
有时,在应用程序中进行长途旅行后,我会收到DeadObjectException,并且所有内存分配都被释放。
我怎样才能检测到这个问题?
我对DDMS工具来检测内存泄漏做了一些研究,由于我不知道DeadObjectExeption
,我不知道从哪里开始。
I have successfully finished an Android project's implementation and started to test the app for memory leaks.
Sometimes, I get DeadObjectException
after a long trip in the app and all of the memory allocations are freed.
How can I detect this problem?
I have made some research about DDMS tools to detect memory leaks, Due to I have no idea about DeadObjectExeption
, I don't know where to start.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不是内存泄漏问题。内存泄漏的定义(来自维基百科):
在这里,您有一个相反的情况 - 内存在应该释放之前被释放(至少从程序的角度来看)。
来自developer.android.com:
例如:
您有类
MyActivity
和 <代码>我的服务。您使用Handler
/Messenger
在它们之间进行通信。您在
MyActivity
中创建Handler
和Messenger
,然后将创建的Messenger
实例发送到MyService 通过
Intent
。然后你做了一些事情,时间过去了,你的MyActivity
连同它的Handler
和Messenger
一起被销毁。现在,如果你处理得不好,MyService
将不知道他拥有的Messenger
不再有效,因此,他尝试通过它发送一些东西,并获取DeadObjectException
:This is not a memory leak problem. Definition of the memory leak (from Wikipedia):
Here, you have an opposite case - memory is freed before it should (at least from your program's point of view).
From developer.android.com:
For example:
You have the classes
MyActivity
andMyService
. You useHandler
/Messenger
to communicate between them.You create
Handler
andMessenger
inMyActivity
, and then send created instance ofMessenger
toMyService
via anIntent
. Then you do some stuff, time passes, and yourMyActivity
gets destroyed, together with it'sHandler
andMessenger
. Now, if you don't handle that well,MyService
won't know thatMessenger
that he has is not valid any more, so, he tries to send something through it, and getDeadObjectexception
:如果您从本机库(.so 文件)调用任何函数,只需检查创建 JNI 函数时使用的包名称是否与您在 Java 类中声明本机方法相同。
If You are calling any function from Native Library(.so file), Just check the package name used while creating JNI function is same as you are declaring native method in Java class.