Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
249 views
in Technique[技术] by (71.8m points)

android - How to fix problem with DeadObjectException?

I have successfully finished an Android project's implementation and started to test the app for memory leaks.

Sometimes, I get DeadObjectExceptionafter 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).

From developer.android.com:

DeadObjectException extends RemoteException

The object you are calling has died, because its hosting process no longer exists.

For example:

You have the classes MyActivity and MyService. 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 an 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 any more, so, he tries to send something through it, and get DeadObjectexception:

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

Parameters:

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

Throws:

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...