Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MTHNetworkObserver类ReceiveData里面appendData的时候,会报NSMallocException内存错误 #63

Open
qcliwei opened this issue Jul 15, 2020 · 3 comments

Comments

@qcliwei
Copy link

qcliwei commented Jul 15, 2020

作者你好:
我这边监听直播推流请求的时候,发现会crash,看了崩溃日志,提示NSMallocException 错误

代码定位到

- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data impl:(id)impl

函数是

[NSConcreteMutableData  appendbytes:length]
[NSConcreteMutableData  appendData:]

我看dataAccumulator逻辑是
didReceiveResponse 初始化
didReceiveData 里面拼接
didCompleteWithError 后面计算大小,移除

有没可能一开始dataAccumulator这个初始化的时候申请内存小了,然后后面不断拼返回的data,造成内存OOM了,直播的时候可能时间很长,导致数据越来越大,dataAccumulator这部分内存没有到didCompleteWithError就没有清除

@qcliwei qcliwei changed the title ReceiveData里面appendData的时候,会报NSMallocException内存错误 MTHNetworkObserver类ReceiveData里面appendData的时候,会报NSMallocException内存错误 Jul 15, 2020
@euanchan
Copy link
Collaborator

之前这个组件未考虑适配这个场景,方便的话能否提供个 MR?
可以加个开关,默认关闭 data 统计这部分功能;或者针对 data 统计做不同场景优化,只对小数据进行本地缓存

@qcliwei
Copy link
Author

qcliwei commented Jul 20, 2020

MR是什么啊?
我这边去掉dataAccumulator拼接逻辑了,我在didCompleteWithError里直接拿Response的length了,不知道这样计算的Response的长度准不准

@euanchan
Copy link
Collaborator

Merge Request(Pull Request) https://github.com/meitu/MTHawkeye/blob/develop/Contributing.md

这个长度不是实际的长度,但可以作为粗略的参考

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants