Skip to content

EaseExecutor存在内存泄漏 #20

@jinanzhuan

Description

@jinanzhuan

内存泄漏信息:
┬───
│ GC Root: Thread object

├─ java.lang.Thread instance
│ Leaking: UNKNOWN
│ Retaining 1.5 MB in 5990 objects
│ Thread name: 'EasyExecutor'
│ ↓ Thread.uncaughtExceptionHandler
│ ~~~~~~~~~~~~~~~~~~~~~~~~
├─ com.haoge.easyandroid.easy.EasyExecutor$TaskWrapper$run$1 instance
│ Leaking: UNKNOWN
│ Retaining 1.5 MB in 5975 objects
│ Anonymous class implementing java.lang.Thread$UncaughtExceptionHandler
│ ↓ EasyExecutor$TaskWrapper$run$1.this$0
│ ~~~~~~
├─ com.haoge.easyandroid.easy.EasyExecutor$TaskWrapper instance
│ Leaking: UNKNOWN
│ Retaining 1.5 MB in 5974 objects
│ ↓ EasyExecutor$TaskWrapper.result
│ ~~~~~~
├─ io.agora.chatdemo.av.DemoCallKitListener$2 instance
│ Leaking: UNKNOWN
│ Retaining 1.5 MB in 5970 objects
│ Anonymous class implementing kotlin.jvm.functions.Function1
│ ↓ DemoCallKitListener$2.val$callback
│ ~~~~~~~~~~~~
├─ io.agora.chat.callkit.ui.EaseCallSingleBaseActivity$3 instance
│ Leaking: UNKNOWN
│ Retaining 1.5 MB in 5969 objects
│ Anonymous class implementing io.agora.chat.callkit.listener.EaseCallKitTokenCallback
│ this$0 instance of io.agora.chatdemo.av.CallSingleBaseActivity with mDestroyed = true
│ ↓ EaseCallSingleBaseActivity$3.this$0
│ ~~~~~~
╰→ io.agora.chatdemo.av.CallSingleBaseActivity instance
​ Leaking: YES (ObjectWatcher was watching this because io.agora.chatdemo.av.CallSingleBaseActivity received
​ Activity#onDestroy() callback and Activity#mDestroyed is true)
​ Retaining 1.5 MB in 5968 objects
​ key = 3c87f3d8-f77b-470e-ac32-9f733bb87aff
​ watchDurationMillis = 10939
​ retainedDurationMillis = 5938
​ mApplication instance of io.agora.chatdemo.DemoApplication
​ mBase instance of androidx.appcompat.view.ContextThemeWrapper

代码中使用如下:
public class DemoCallKitListener implements EaseCallKitListener {

...
private final EasyExecutor executor;
...

public DemoCallKitListener(Context context, UsersManager usersManager) {
    this.mContext = context;
    this.mUsersManager = usersManager;
    executor = EasyExecutor.newBuilder(0)
            .build();
}

@Override
public void onGenerateRTCToken(String userAccount, String channelName, EaseCallKitTokenCallback callback) {
    
    StringBuilder url = buildUrl(userAccount, channelName);

    getRtcToken(url.toString(), agoraUid, callback);
}


private void getRtcToken(String tokenUrl, int agoraUid, EaseCallKitTokenCallback callback) {
    executor.asyncResult(new Function1<Pair<Integer, String>, Unit>() {
        @Override
        public Unit invoke(Pair<Integer, String> response) {
           ...
                                JSONObject object = new JSONObject(responseInfo);
                                String token = object.getString("accessToken");
                                //Set your avatar nickname
                                setEaseCallKitUserInfo(ChatClient.getInstance().getCurrentUser());
                                callback.onSetToken(token, agoraUid);
            ...
            return null;
        }
    })
            .asyncTask(notifier -> {
                try {
                    Pair<Integer, String> response = EMHttpClient.getInstance().sendRequestWithToken(tokenUrl, null, EMHttpClient.GET);
                    return response;
                } catch (ChatException exception) {
                    exception.printStackTrace();
                }
                return null;
            });
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions