aliyun / aliyun-log-android-sdk

MIT License
180 stars 40 forks source link

发现一个容易引发 OOM 的问题。 #20

Closed captain-miao closed 5 years ago

captain-miao commented 5 years ago

循环创建 AsyncTask,这样容易引发 OOM,支持批量上传比较好。

CacheManager.java 84行


    private void fetchDataFromDBAndPost() {
        List<LogEntity> list = SLSDatabaseManager.getInstance().queryRecordFromDB();
        for (final LogEntity item : list) {
            String clientEndPoint = this.mClient.GetEndPoint();
            if (clientEndPoint.equals(item.getEndPoint())) {
                try {
                    PostCachedLogRequest request = new PostCachedLogRequest(item.getProject(), item.getStore(), item.getJsonString());
                    AsyncTask<PostCachedLogResult> result = this.mClient.asyncPostCachedLog(request, new CompletedCallback<PostCachedLogRequest, PostCachedLogResult>() {
                        @Override
                        public void onSuccess(PostCachedLogRequest request, PostCachedLogResult result) {
                            SLSDatabaseManager.getInstance().deleteRecordFromDB(item);
                        }

                        @Override
                        public void onFailure(PostCachedLogRequest request, LogException exception) {
                            SLSLog.logError("send cached log failed");
                        }
                    });
                } catch (LogException e) {
                    e.printStackTrace();
                }
            }
        }
    }
naruto-wbb commented 5 years ago

这个貌似问题不大