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

内存泄露 #48

Open
ztc464728422 opened this issue Aug 3, 2021 · 11 comments
Open

内存泄露 #48

ztc464728422 opened this issue Aug 3, 2021 · 11 comments

Comments

@ztc464728422
Copy link

您好,您的开源框架是少数几个能在机顶盒上做复杂序列帧动画不卡的。
现在我遇到一个比较严重的内存泄露问题,我再一个页面中,不断的清除、新增 多个 FrameAnimation控件播放多个序列帧,平均1小时左右,内存占用会在1分钟内突然持续大量增长,直到最终由decodeBitmap()触发OOM。OOM页面闪退后,泄露内存依然无法释放

#125006 java.lang.OutOfMemoryError
pthread_create (1040KB stack) failed: Try again
com.yuyashuai.frameanimation.io.BitmapPoolImpl.void decodeBitmap()(BitmapPoolImpl.java:154)

@ztc464728422
Copy link
Author

播放的图片序列帧,一般是7s 24fps 每张图大约100K左右,100-200张

@ztc464728422
Copy link
Author

泄露的内存为native内存

@ztc464728422
Copy link
Author

由于序列帧图片大小非降序,没有开启图片复用

@yuyashuai
Copy link
Owner

在一个页面中,不断的清除、新增多个 FrameAnimation控件播放多个序列帧。
是指一直新增多个FrameAnimationView吗,还是一直使用同一个FrameAnimationView播放不同的动画呢。最好有简单的代码示例。

@ztc464728422
Copy link
Author

具体的场景是一组动态图播完一定时间后,清理,替换新一批动态图,每张动态图位置、大小都不同。

当前采用先移除后新增多个FrameAnimationView,完成2批动态图的切换。

加载代码如下:tvContent为FrameAnimationView

tvContent.setRepeatMode(FrameAnimation.RepeatMode.INFINITE);
tvContent.setScaleType(FrameAnimation.ScaleType.FIT_CENTER);
ArrayList fileslist = FileSort.orderByName(path);
if(fileslist == null) return;
ArrayList<FrameAnimation.PathData> t = new ArrayList<>();
for(String x : fileslist ){
FrameAnimation.PathData v = new FrameAnimation.PathData(x,FrameAnimation.getPATH_FILE());
t.add(v);
}
if(t.size()<100){
tvContent.setFrameInterval(80);
}else{
tvContent.setFrameInterval(40);
}
tvContent.setSupportInBitmap(false);
tvContent.playAnimation(t);

@ztc464728422
Copy link
Author

通过android 手机的测试,再手机中连续进行上述操作,1次在2小时后,1次再4小时,也都出现了app卡死的情况,通过bugly手机错误信息如下,并检测到此时存在大量线程,包括16个 图片解码DecodeThread 线程:

IntentServiceHeapAnalyzerService

java.lang.IllegalStateException

Cannot perform this operation because there is no current transaction.

1
android.database.sqlite.SQLiteSession.throwIfNoTransaction(SQLiteSession.java:915)
2
android.database.sqlite.SQLiteSession.endTransaction(SQLiteSession.java:398)
3
android.database.sqlite.SQLiteDatabase.endTransaction(SQLiteDatabase.java:566)
4
leakcanary.internal.activity.db.HeapAnalysisTable.insert(HeapAnalysisTable.kt:217)
5
leakcanary.DefaultOnHeapAnalyzedListener.onHeapAnalyzed(DefaultOnHeapAnalyzedListener.kt:46)
6
leakcanary.internal.HeapAnalyzerService.onHandleIntentInForeground(HeapAnalyzerService.kt:73)
7
leakcanary.internal.ForegroundService.onHandleIntent(ForegroundService.kt:55)
8
android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:76)
9
android.os.Handler.dispatchMessage(Handler.java:106)
10
android.os.Looper.loop(Looper.java:224)
11
android.os.HandlerThread.run(HandlerThread.java:65)

@ztc464728422
Copy link
Author

我这边对log日志中的大量GC操作有些疑惑,不知道是否可能是产生上述异常的原因之一
Explicit concurrent copying GC freed 784(323KB) AllocSpace objects, 3(60KB) LOS objects, 49% free, 15MB/31MB, paused 389us total 41.117ms

Waiting for a blocking GC Explicit

WaitForGcToComplete blocked NativeAlloc on HeapTrim for 22.765ms

@yuyashuai
Copy link
Owner

我这边对log日志中的大量GC操作有些疑惑,不知道是否可能是产生上述异常的原因之一
Explicit concurrent copying GC freed 784(323KB) AllocSpace objects, 3(60KB) LOS objects, 49% free, 15MB/31MB, paused 389us total 41.117ms

Waiting for a blocking GC Explicit

WaitForGcToComplete blocked NativeAlloc on HeapTrim for 22.765ms

关闭图片复用会导致内存抖动,频繁GC。

@yuyashuai
Copy link
Owner

通过android 手机的测试,再手机中连续进行上述操作,1次在2小时后,1次再4小时,也都出现了app卡死的情况,通过bugly手机错误信息如下,并检测到此时存在大量线程,包括16个 图片解码DecodeThread 线程:

IntentServiceHeapAnalyzerService

java.lang.IllegalStateException

Cannot perform this operation because there is no current transaction.

1
android.database.sqlite.SQLiteSession.throwIfNoTransaction(SQLiteSession.java:915)
2
android.database.sqlite.SQLiteSession.endTransaction(SQLiteSession.java:398)
3
android.database.sqlite.SQLiteDatabase.endTransaction(SQLiteDatabase.java:566)
4
leakcanary.internal.activity.db.HeapAnalysisTable.insert(HeapAnalysisTable.kt:217)
5
leakcanary.DefaultOnHeapAnalyzedListener.onHeapAnalyzed(DefaultOnHeapAnalyzedListener.kt:46)
6
leakcanary.internal.HeapAnalyzerService.onHandleIntentInForeground(HeapAnalyzerService.kt:73)
7
leakcanary.internal.ForegroundService.onHandleIntent(ForegroundService.kt:55)
8
android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:76)
9
android.os.Handler.dispatchMessage(Handler.java:106)
10
android.os.Looper.loop(Looper.java:224)
11
android.os.HandlerThread.run(HandlerThread.java:65)

crash堆栈看起来跟这个库没有关系。
如果使用不同的FrameAnimationView有可能会导致pthread_create的OOM,每个FrameAnimationView都会创建一个线程池,动画结束30s后线程池中的线程才会释放。

@ztc464728422
Copy link
Author

以下两种基本确认为现在的主要报错信息,不过没有再看到内存出现明显增长了。

RenderThread(2948)

SIGABRT

1
#00 pc 0000000000021c64 /system/lib64/libc.so (abort+116) [arm64-v8a::4c858f43e4c53e13d8b16076bc0deb8b]
2
#1 pc 0000000000008080 /system/lib64/liblog.so (__android_log_assert+304) [arm64-v8a::25bdde3b307eb462dcd3edc2b1cdc14d]
3
#2 pc 000000000047fd0c /system/lib64/libhwui.so [arm64-v8a::c74c69ae14b18d6207d134f9048d2457]
4
#3 pc 0000000000479b60 /system/lib64/libhwui.so [arm64-v8a::c74c69ae14b18d6207d134f9048d2457]
5
#4 pc 00000000001076a8 /system/lib64/libhwui.so [arm64-v8a::c74c69ae14b18d6207d134f9048d2457]
6
#5 pc 000000000047e708 /system/lib64/libhwui.so [arm64-v8a::c74c69ae14b18d6207d134f9048d2457]
7
#6 pc 00000000004363f8 /system/lib64/libhwui.so [arm64-v8a::c74c69ae14b18d6207d134f9048d2457]
8
#7 pc 0000000000114620 /system/lib64/libhwui.so [arm64-v8a::c74c69ae14b18d6207d134f9048d2457]
9
#8 pc 000000000000f9d8 /system/lib64/libutils.so (android::Thread::_threadLoop(void*)+280) [arm64-v8a::00e8423097ba3cc6f45b26e29a2b8fe7]
10
#9 pc 0000000000083090 /system/lib64/libc.so (__pthread_start(void*)+36) [arm64-v8a::4c858f43e4c53e13d8b16076bc0deb8b]
11
#10 pc 00000000000234c8 /system/lib64/libc.so (__start_thread+68) [arm64-v8a::4c858f43e4c53e13d8b16076bc0deb8b]
12
java:

HeapTaskDaemon(246)

SIGABRT

解析原始
1
#00 pc 0001ce72 /system/lib/libc.so (abort+61) [armeabi-v7a::0ab03097f7b50ae290834de3a56ac8a4]
2
#1 pc 00053b8b /system/lib/libc.so (__stack_chk_fail+10) [armeabi-v7a::0ab03097f7b50ae290834de3a56ac8a4]
3
#2 pc 0016529d /system/lib/libart.so (void art::gc::collector::ConcurrentCopying::MarkRoot(art::mirror::CompressedReferenceart::mirror::Object)+420) [armeabi-v7a::45c4b80725d8e71cf2064664325158d1]
4
#3 pc 00164c0b /system/lib/libart.so (void art::mirror::Object::VisitReferences<true, (art::VerifyObjectFlags)0, (art::ReadBarrierOption)1, art::gc::collector::ConcurrentCopying::RefFieldsVisitor, art::gc::collector::ConcurrentCopying::RefFieldsVisitor>(art::gc::collector::ConcurrentCopying::RefFieldsVisitor const&, art::gc::collector::ConcurrentCopying::RefFieldsVisitor const&)+1846) [armeabi-v7a::45c4b80725d8e71cf2064664325158d1]
5
#4 pc 0015e00f /system/lib/libart.so (art::gc::collector::ConcurrentCopying::ProcessMarkStackRef(art::mirror::Object
)+98) [armeabi-v7a::45c4b80725d8e71cf2064664325158d1]
6
#5 pc 0015dadd /system/lib/libart.so (art::gc::collector::ConcurrentCopying::ProcessMarkStackOnce()+520) [armeabi-v7a::45c4b80725d8e71cf2064664325158d1]
7
#6 pc 0015d8c1 /system/lib/libart.so (art::gc::collector::ConcurrentCopying::ProcessMarkStack()+8) [armeabi-v7a::45c4b80725d8e71cf2064664325158d1]
8
#7 pc 001585b7 /system/lib/libart.so (art::gc::collector::ConcurrentCopying::MarkingPhase()+1314) [armeabi-v7a::45c4b80725d8e71cf2064664325158d1]
9
#8 pc 001570a3 /system/lib/libart.so (art::gc::collector::ConcurrentCopying::RunPhases()+890) [armeabi-v7a::45c4b80725d8e71cf2064664325158d1]
10
#9 pc 00167eb3 /system/lib/libart.so (art::gc::collector::GarbageCollector::Run(art::gc::GcCause, bool)+250) [armeabi-v7a::45c4b80725d8e71cf2064664325158d1]
11
#10 pc 00181e97 /system/lib/libart.so (art::gc::Heap::CollectGarbageInternal(art::gc::collector::GcType, art::gc::GcCause, bool)+2502) [armeabi-v7a::45c4b80725d8e71cf2064664325158d1]
12
#11 pc 0018fa69 /system/lib/libart.so (art::gc::Heap::ConcurrentGC(art::Thread*, art::gc::GcCause, bool)+72) [armeabi-v7a::45c4b80725d8e71cf2064664325158d1]
13
#12 pc 00193981 /system/lib/libart.so (art::gc::Heap::ConcurrentGCTask::Run(art::Thread*)+20) [armeabi-v7a::45c4b80725d8e71cf2064664325158d1]
14
#13 pc 001acb53 /system/lib/libart.so (art::gc::TaskProcessor::RunAllTasks(art::Thread*)+34) [armeabi-v7a::45c4b80725d8e71cf2064664325158d1]
15
#14 pc 0000163b /system/framework/arm/boot-core-libart.oat (oatdata+1595) [armeabi::9c38902979657431722ddcda834ff079]
16

@yuyashuai
Copy link
Owner

以下两种基本确认为现在的主要报错信息,不过没有再看到内存出现明显增长了。

RenderThread(2948)

SIGABRT

1
#0 pc 0000000000021c64 /system/lib64/libc.so (abort+116) [arm64-v8a::4c858f43e4c53e13d8b16076bc0deb8b]
2
#1 pc 0000000000008080 /system/lib64/liblog.so (__android_log_assert+304) [arm64-v8a::25bdde3b307eb462dcd3edc2b1cdc14d]
3
#2 pc 000000000047fd0c /system/lib64/libhwui.so [arm64-v8a::c74c69ae14b18d6207d134f9048d2457]
4
#3 pc 0000000000479b60 /system/lib64/libhwui.so [arm64-v8a::c74c69ae14b18d6207d134f9048d2457]
5
#4 pc 00000000001076a8 /system/lib64/libhwui.so [arm64-v8a::c74c69ae14b18d6207d134f9048d2457]
6
#5 pc 000000000047e708 /system/lib64/libhwui.so [arm64-v8a::c74c69ae14b18d6207d134f9048d2457]
7
#6 pc 00000000004363f8 /system/lib64/libhwui.so [arm64-v8a::c74c69ae14b18d6207d134f9048d2457]
8
#7 pc 0000000000114620 /system/lib64/libhwui.so [arm64-v8a::c74c69ae14b18d6207d134f9048d2457]
9
#8 pc 000000000000f9d8 /system/lib64/libutils.so (android::Thread::_threadLoop(void*)+280) [arm64-v8a::00e8423097ba3cc6f45b26e29a2b8fe7]
10
#9 pc 0000000000083090 /system/lib64/libc.so (__pthread_start(void*)+36) [arm64-v8a::4c858f43e4c53e13d8b16076bc0deb8b]
11
#10 pc 00000000000234c8 /system/lib64/libc.so (__start_thread+68) [arm64-v8a::4c858f43e4c53e13d8b16076bc0deb8b]
12
java:

HeapTaskDaemon(246)

SIGABRT

解析原始
1
#0 pc 0001ce72 /system/lib/libc.so (abort+61) [armeabi-v7a::0ab03097f7b50ae290834de3a56ac8a4]
2
#1 pc 00053b8b /system/lib/libc.so (stack_chk_fail+10) [armeabi-v7a::0ab03097f7b50ae290834de3a56ac8a4]
3
#2 pc 0016529d /system/lib/libart.so (void art::gc::collector::ConcurrentCopying::MarkRoot(art:🪞:CompressedReferenceart:🪞:Object
)+420) [armeabi-v7a::45c4b80725d8e71cf2064664325158d1] 4 #3 pc 00164c0b /system/lib/libart.so (void art:🪞:Object::VisitReferences<true, (art::VerifyObjectFlags)0, (art::ReadBarrierOption)1, art::gc::collector::ConcurrentCopying::RefFieldsVisitor, art::gc::collector::ConcurrentCopying::RefFieldsVisitor>(art::gc::collector::ConcurrentCopying::RefFieldsVisitor const&, art::gc::collector::ConcurrentCopying::RefFieldsVisitor const&)+1846) [armeabi-v7a::45c4b80725d8e71cf2064664325158d1] 5 #4 pc 0015e00f /system/lib/libart.so (art::gc::collector::ConcurrentCopying::ProcessMarkStackRef(art:🪞:Object
)+98) [armeabi-v7a::45c4b80725d8e71cf2064664325158d1]
6
#5 pc 0015dadd /system/lib/libart.so (art::gc::collector::ConcurrentCopying::ProcessMarkStackOnce()+520) [armeabi-v7a::45c4b80725d8e71cf2064664325158d1]
7
#6 pc 0015d8c1 /system/lib/libart.so (art::gc::collector::ConcurrentCopying::ProcessMarkStack()+8) [armeabi-v7a::45c4b80725d8e71cf2064664325158d1]
8
#7 pc 001585b7 /system/lib/libart.so (art::gc::collector::ConcurrentCopying::MarkingPhase()+1314) [armeabi-v7a::45c4b80725d8e71cf2064664325158d1]
9
#8 pc 001570a3 /system/lib/libart.so (art::gc::collector::ConcurrentCopying::RunPhases()+890) [armeabi-v7a::45c4b80725d8e71cf2064664325158d1]
10
#9 pc 00167eb3 /system/lib/libart.so (art::gc::collector::GarbageCollector::Run(art::gc::GcCause, bool)+250) [armeabi-v7a::45c4b80725d8e71cf2064664325158d1]
11
#10 pc 00181e97 /system/lib/libart.so (art::gc::Heap::CollectGarbageInternal(art::gc::collector::GcType, art::gc::GcCause, bool)+2502) [armeabi-v7a::45c4b80725d8e71cf2064664325158d1]
12
#11 pc 0018fa69 /system/lib/libart.so (art::gc::Heap::ConcurrentGC(art::Thread*, art::gc::GcCause, bool)+72) [armeabi-v7a::45c4b80725d8e71cf2064664325158d1]
13
#12 pc 00193981 /system/lib/libart.so (art::gc::Heap::ConcurrentGCTask::Run(art::Thread*)+20) [armeabi-v7a::45c4b80725d8e71cf2064664325158d1]
14
#13 pc 001acb53 /system/lib/libart.so (art::gc::TaskProcessor::RunAllTasks(art::Thread*)+34) [armeabi-v7a::45c4b80725d8e71cf2064664325158d1]
15
#14 pc 0000163b /system/framework/arm/boot-core-libart.oat (oatdata+1595) [armeabi::9c38902979657431722ddcda834ff079]
16
这些堆栈看起来关系也不大。

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