Android的死亡对象异常 [英] Android Dead Object Exception

查看:556
本文介绍了Android的死亡对象异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功地完成了一个机器人项目的实施,并开始测试内存泄漏的应用程序。有时候,我以后在应用程序中的长途旅行让deadobject例外,所有的内存分配被释放。我怎样才能检测到这个问题?我已就DDMS工具的一些研究,以检测内存泄漏,由于我不知道关于DeadObjectExeption,我不知道从哪里开始。

I have successfully finished an android project's implementation and started to test the app for memory leaks. Sometimes, I get deadobject exception 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.

在此先感谢。

推荐答案

这是不是一个内存泄漏问题。 (来自维基百科)的内存泄漏的定义:

This is not a memory leak problem. Definition of the memory leak (from Wikipedia):

有一个内存泄漏,在计算机科学(或泄漏,在这种情况下),   当一个计算机程序获取内存,但未能将其释放时   回操作系统

A memory leak, in computer science (or leakage, in this context), occurs when a computer program acquires memory but fails to release it back to the operating system.

在这里,你有一个相反的情况 - 内存被释放之前,它应该(至少但从程序的点)

Here, you have an opposite case - memory is freed before it should (at least from your program's point of view).

从developer.android.com:

From developer.android.com:

DeadObjectException 扩展的RemoteException

DeadObjectException extends RemoteException

您呼叫的对象已经死了,因为它的宿主进程不再存在。

例如:

您已经MyActivity并为MyService类。您可以使用处理器/斜挎它们之间的通信。 您在MyActivity创建处理程序和Messenger,然后通过意向发送的Messenger创建的实例为了My​​Service。然后,你做一些东西,久而久之,你的MyActivity被破坏,再加上它的处理程序和Messenger。现在,如果你不处理那么好,为MyService不会知道使者,他已经不再有效,因此,他试图通过它来送东西,并获得DeadObjectexception:

You have MyActivity and MyService classes. You use Handler/Messenger to communicate between them. You create Handler and Messenger in MyActivity, and then send created instance of Messenger to MyService via Intent. Then you do some stuff, time passes, and your MyActivity gets destroyed, together with it's Handler and Messenger. Now, if you don't handle that well, MyService won't know that Messenger that he has is not valid anymore, so, he tries to send something through it, and get DeadObjectexception:

/ *   发送邮件到该通的处理器。

/* Send a Message to this Messenger's Handler.

参数:

消息要发送的消息。通常通过Message.obtain()进行检索。

message The Message to send. Usually retrieved through Message.obtain().

抛出:

的RemoteException 抛出DeadObjectException如果目标Handler不再存在。* /

RemoteException Throws DeadObjectException if the target Handler no longer exists.*/

公共无效发送(消息消息)将抛出RemoteException {...}

public void send(Message message) throws RemoteException {...}

这篇关于Android的死亡对象异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆