我有一个ListView。每个ListViewItem主要是一个具有不同数量图像的LinearLayout。所以当我重用ListViewItem时,我会调用
mediaLinear.RemoveAllViewsInlayout();
然后foreach数据输入我正在插入新的ImageView:
public override View GetView (int position, View convertView, ViewGroup parent)
{
if (convertView == null) {
convertView = LayoutInflater.From (_context).Inflate (Resource.Layout.PostsListItem, null);
}
...
LinearLayout mediaLinear = convertView.FindViewById<LinearLayout> (Resource.Id.post_media);
mediaLinear.RemoveAllViewsInLayout ();
var ats = DBWorker.Instance.Connection.Table<Core.Local.Attachment> ().Where (...);
foreach (var att in ats.ToListAsync().Result) {
var im = new ImageView (_context); //exception here
_memoryCache.SetImage (_context, im, att.url, MainActivity.TempFolder).ConfigureAwait(false);
mediaLinear.AddView (im);
}
...
return convertView;
}
如何正确解决这个问题?
[art] Clamp target GC heap from 111MB to 96MB
[art] Clamp target GC heap from 111MB to 96MB
[art] Alloc partial concurrent mark sweep GC freed 45(1728B) AllocSpace objects, 2(32KB) LOS objects, 0% free, 95MB/96MB, paused 1.368ms total 13.142ms
no cache for item
55868 Childs count: 1
......
[art] native: #36 pc 000ad117 /data/dalvik-cache/x86/data@app@com-1@base.apk@classes.dex (Java_md51390a9bb27ae81984ed2b5a51b13bec9_PostsListViewAdapter_n_1getView__ILandroid_view_View_2Landroid_view_ViewGroup_2+187)
[art] at md51390a9bb27ae81984ed2b5a51b13bec9.PostsListViewAdapter.n_getView(Native method)
[art] at md51390a9bb27ae81984ed2b5a51b13bec9.PostsListViewAdapter.getView(PostsListViewAdapter.java:46)
[art] at android.widget.AbsListView.obtainView(AbsListView.java:2347)
[art] at android.widget.ListView.makeAndAddView(ListView.java:1864)
[art] at android.widget.ListView.fillUp(ListView.java:732)
[art] at android.widget.ListView.fillGap(ListView.java:671)
[art] at android.widget.AbsListView.trackMotionScroll(AbsListView.java:4991)
[art] at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:4539)
[art] at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
[art] at android.view.Choreographer.doCallbacks(Choreographer.java:580)
[art] at android.view.Choreographer.doFrame(Choreographer.java:549)
[art] at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
[art] at android.os.Handler.handleCallback(Handler.java:739)
[art] at android.os.Handler.dispatchMessage(Handler.java:95)
[art] at android.os.Looper.loop(Looper.java:135)
[art] at android.app.ActivityThread.main(ActivityThread.java:5254)
[art] at java.lang.reflect.Method.invoke!(Native method)
[art] at java.lang.reflect.Method.invoke(Method.java:372)
[art] at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
[art] at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
[Mono] Assembly Ref addref Mono.Android[0xf3fca100] -> System.Runtime.Serialization[0xd9adde80]: 3
[art] Clamp target GC heap from 111MB to 96MB
[art] Alloc partial concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 569us total 11.319ms
[art] Clamp target GC heap from 111MB to 96MB
[art] Alloc concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 626us total 17.213ms
[art] Forcing collection of SoftReferences for 20B allocation
[art] Clamp target GC heap from 111MB to 96MB
[art] Alloc concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 537us total 15.912ms
[art] Throwing OutOfMemoryError "Failed to allocate a 20 byte allocation with 16 free bytes and 16B until OOM"
[art] Clamp target GC heap from 111MB to 96MB
[art] Alloc partial concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 1.183ms total 13.635ms
[art] Clamp target GC heap from 111MB to 96MB
[art] Alloc concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 968us total 18.755ms
[art] Forcing collection of SoftReferences for 28B allocation
[art] Clamp target GC heap from 111MB to 96MB
[art] Alloc concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 1.653ms total 17.441ms
[art] Throwing OutOfMemoryError "Failed to allocate a 28 byte allocation with 16 free bytes and 16B until OOM" (recursive case)
[art] "main" prio=5 tid=1 Runnable
[art] | group="main" sCount=0 dsCount=0 obj=0x739e6000 self=0xf3c25800
[art] | sysTid=16583 nice=-6 cgrp=default sched=0/0 handle=0xf7711ea0
[art] | state=R schedstat=( 51640943258 3602210510 26084 ) utm=3430 stm=1733 core=2 HZ=100
[art] | stack=0xff04c000-0xff04e000 stackSize=8MB
[art] | held mutexes= "mutator lock"(shared held)
[art] at android.view.View.toString(View.java:4250)
[art] at md51390a9bb27ae81984ed2b5a51b13bec9.PostsListViewAdapter.n_getView(Native method)
[art] at md51390a9bb27ae81984ed2b5a51b13bec9.PostsListViewAdapter.getView(PostsListViewAdapter.java:46)
[art] at android.widget.AbsListView.obtainView(AbsListView.java:2347)
[art] at android.widget.ListView.makeAndAddView(ListView.java:1864)
[art] at android.widget.ListView.fillUp(ListView.java:732)
[art] at android.widget.ListView.fillGap(ListView.java:671)
[art] at android.widget.AbsListView.trackMotionScroll(AbsListView.java:4991)
[art] at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:4539)
[art] at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
[art] at android.view.Choreographer.doCallbacks(Choreographer.java:580)
[art] at android.view.Choreographer.doFrame(Choreographer.java:549)
[art] at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
[art] at android.os.Handler.handleCallback(Handler.java:739)
[art] at android.os.Handler.dispatchMessage(Handler.java:95)
[art] at android.os.Looper.loop(Looper.java:135)
[art] at android.app.ActivityThread.main(ActivityThread.java:5254)
[art] at java.lang.reflect.Method.invoke!(Native method)
[art] at java.lang.reflect.Method.invoke(Method.java:372)
[art] at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
[art] at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
[art] Alloc sticky concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 5.480ms total 7.922ms
[art] Clamp target GC heap from 111MB to 96MB
[art] Alloc partial concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 1.134ms total 16.326ms
[art] Clamp target GC heap from 111MB to 96MB
[art] Alloc concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 892us total 17.164ms
[art] Forcing collection of SoftReferences for 20B allocation
[art] Clamp target GC heap from 111MB to 96MB
[art] Alloc concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 1.042ms total 17.104ms
[art] Throwing OutOfMemoryError "Failed to allocate a 20 byte allocation with 16 free bytes and 16B until OOM"
[art] Clamp target GC heap from 111MB to 96MB
[art] Alloc partial concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 1.701ms total 16.814ms
[art] Clamp target GC heap from 111MB to 96MB
[art] Alloc concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 1.728ms total 17.024ms
[art] Forcing collection of SoftReferences for 28B allocation
[art] Clamp target GC heap from 111MB to 96MB
[art] Alloc concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 643us total 17.888ms
[art] Throwing OutOfMemoryError "Failed to allocate a 28 byte allocation with 16 free bytes and 16B until OOM" (recursive case)
[art] "main" prio=5 tid=1 Runnable
[art] | group="main" sCount=0 dsCount=0 obj=0x739e6000 self=0xf3c25800
[art] | sysTid=16583 nice=-6 cgrp=default sched=0/0 handle=0xf7711ea0
[art] | state=R schedstat=( 51750576514 3606256916 26097 ) utm=3438 stm=1736 core=3 HZ=100
[art] | stack=0xff04c000-0xff04e000 stackSize=8MB
[art] | held mutexes= "mutator lock"(shared held)
[art] at android.view.View.toString(View.java:4250)
[art] at md51390a9bb27ae81984ed2b5a51b13bec9.PostsListViewAdapter.n_getView(Native method)
[art] at md51390a9bb27ae81984ed2b5a51b13bec9.PostsListViewAdapter.getView(PostsListViewAdapter.java:46)
[art] at android.widget.AbsListView.obtainView(AbsListView.java:2347)
[art] at android.widget.ListView.makeAndAddView(ListView.java:1864)
[art] at android.widget.ListView.fillUp(ListView.java:732)
[art] at android.widget.ListView.fillGap(ListView.java:671)
[art] at android.widget.AbsListView.trackMotionScroll(AbsListView.java:4991)
[art] at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:4539)
[art] at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
[art] at android.view.Choreographer.doCallbacks(Choreographer.java:580)
[art] at android.view.Choreographer.doFrame(Choreographer.java:549)
[art] at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
[art] at android.os.Handler.handleCallback(Handler.java:739)
[art] at android.os.Handler.dispatchMessage(Handler.java:95)
[art] at android.os.Looper.loop(Looper.java:135)
[art] at android.app.ActivityThread.main(ActivityThread.java:5254)
[art] at java.lang.reflect.Method.invoke!(Native method)
[art] at java.lang.reflect.Method.invoke(Method.java:372)
[art] at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
[art] at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
[art] Clamp target GC heap from 111MB to 96MB
[art] Alloc partial concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 592us total 13.027ms
[art] Clamp target GC heap from 111MB to 96MB
[art] Alloc concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 844us total 16.250ms
[art] Forcing collection of SoftReferences for 52B allocation
[art] Clamp target GC heap from 111MB to 96MB
[art] Alloc concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 619us total 15.621ms
[art] Throwing OutOfMemoryError "Failed to allocate a 52 byte allocation with 16 free bytes and 16B until OOM"
[art] Clamp target GC heap from 111MB to 96MB
[art] Alloc partial concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 600us total 10.853ms
[art] Clamp target GC heap from 111MB to 96MB
[art] Alloc concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 920us total 16.905ms
[art] Forcing collection of SoftReferences for 28B allocation
[art] Clamp target GC heap from 111MB to 96MB
[art] Alloc concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 1.314ms total 15.773ms
[art] Throwing OutOfMemoryError "Failed to allocate a 28 byte allocation with 16 free bytes and 16B until OOM" (recursive case)
[art] "main" prio=5 tid=1 Runnable
[art] | group="main" sCount=0 dsCount=0 obj=0x739e6000 self=0xf3c25800
[art] | sysTid=16583 nice=-6 cgrp=default sched=0/0 handle=0xf7711ea0
[art] | state=R schedstat=( 51849796865 3607688955 26109 ) utm=3447 stm=1737 core=3 HZ=100
[art] | stack=0xff04c000-0xff04e000 stackSize=8MB
[art] | held mutexes= "mutator lock"(shared held)
[art] native: #00 pc 00005d03 /system/lib/libbacktrace_libc++.so (UnwindCurrent::Unwind(unsigned int, ucontext*)+83)
[art] native: #01 pc 00003051 /system/lib/libbacktrace_libc++.so (Backtrace::Unwind(unsigned int, ucontext*)+33)
[art] native: #02 pc 003c9b97 /system/lib/libart.so (art::DumpNativeStack(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, int, char const*, art::mirror::ArtMethod*)+135)
[art] native: #03 pc 0038f2c2 /system/lib/libart.so (art::Thread::DumpStack(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const+290)
[art] native: #04 pc 00395bdb /system/lib/libart.so (art::Thread::ThrowOutOfMemoryError(char const*)+459)
[art] native: #05 pc 001f1efb /system/lib/libart.so (art::gc::Heap::ThrowOutOfMemoryError(art::Thread*, unsigned int, art::gc::AllocatorType)+1243)
[art] native: #06 pc 001f5ba5 /system/lib/libart.so (art::gc::Heap::AllocateInternalWithGc(art::Thread*, art::gc::AllocatorType, unsigned int, unsigned int*, unsigned int*, art::mirror::Class**)+2773)
[art] native: #07 pc 0017e1bb /system/lib/libart.so (art::mirror::Class::AllocObject(art::Thread*)+1275)
[art] native: #08 pc 00394dd4 /system/lib/libart.so (art::Thread::ThrowNewWrappedException(art::ThrowLocation const&, char const*, char const*)+820)
[art] native: #09 pc 00395c82 /system/lib/libart.so (art::Thread::ThrowOutOfMemoryError(char const*)+626)
[art] native: #10 pc 001f1efb /system/lib/libart.so (art::gc::Heap::ThrowOutOfMemoryError(art::Thread*, unsigned int, art::gc::AllocatorType)+1243)
[art] native: #11 pc 001f5ba5 /system/lib/libart.so (art::gc::Heap::AllocateInternalWithGc(art::Thread*, art::gc::AllocatorType, unsigned int, unsigned int*, unsigned int*, art::mirror::Class**)+2773)
[art] native: #12 pc 0031eed3 /system/lib/libart.so (art::mirror::String::Alloc(art::Thread*, int)+1955)
[art] native: #13 pc 0031f39d /system/lib/libart.so (art::mirror::String::AllocFromUtf16(art::Thread*, int, unsigned short const*, int)+45)
[art] native: #14 pc 002cb4cb /system/lib/libart.so (art::JNI::NewString(_JNIEnv*, unsigned short const*, int)+363)
[art] native: #15 pc 0010ec4d /system/lib/libart.so (art::CheckJNI::NewString(_JNIEnv*, unsigned short const*, int)+125)
[art] native: #16 pc 00005eb7 (???)
[art] native: #17 pc 000048a2 (???)
[art] native: #18 pc 00004107 (???)
[art] native: #19 pc 00003c8f (???)
[art] native: #20 pc 00003b77 (???)
[art] native: #21 pc 00007bd7 (???)
[art] native: #22 pc 000079fb (???)
[art] native: #23 pc 0000751b (???)
[art] native: #24 pc 0000724d (???)
[art] native: #25 pc 00007354 (???)
[art] native: #26 pc 0002a834 /data/app/Mono.Android.DebugRuntime-1/lib/x86/libmonosgen-32bit-2.0.so (???)
[art] native: #27 pc 001b22cb /data/app/Mono.Android.DebugRuntime-1/lib/x86/libmonosgen-32bit-2.0.so (mono_runtime_invoke+75)
[art] native: #28 pc 000e19bc /data/app/Mono.Android.DebugRuntime-1/lib/x86/libmonosgen-32bit-2.0.so (???)
[art] native: #29 pc 000e2328 /data/app/Mono.Android.DebugRuntime-1/lib/x86/libmonosgen-32bit-2.0.so (???)
[art] native: #30 pc 000e24aa /data/app/Mono.Android.DebugRuntime-1/lib/x86/libmonosgen-32bit-2.0.so (???)
[art] native: #31 pc 000e24aa /data/app/Mono.Android.DebugRuntime-1/lib/x86/libmonosgen-32bit-2.0.so (???)
[art] native: #32 pc 000e24aa /data/app/Mono.Android.DebugRuntime-1/lib/x86/libmonosgen-32bit-2.0.so (???)
[art] native: #33 pc 000e24aa /data/app/Mono.Android.DebugRuntime-1/lib/x86/libmonosgen-32bit-2.0.so (???)
[art] native: #34 pc 000e24aa /data/app/Mono.Android.DebugRuntime-1/lib/x86/libmonosgen-32bit-2.0.so (???)
[art] native: #35 pc 000e24aa /data/app/Mono.Android.DebugRuntime-1/lib/x86/libmonosgen-32bit-2.0.so (???)
[art] native: #36 pc 000e34f9 /data/app/Mono.Android.DebugRuntime-1/lib/x86/libmonosgen-32bit-2.0.so (???)
[art] native: #37 pc 000f0000 /data/app/Mono.Android.DebugRuntime-1/lib/x86/libmonosgen-32bit-2.0.so (???)
[art] native: #38 pc 00007023 (???)
[art] native: #39 pc 00006fc7 (???)
[art] native: #40 pc 0003134b (???)
[art] native: #41 pc 0000df1f (???)
[art] native: #42 pc 000ad117 /data/dalvik-cache/x86/data@app@com@base.apk@classes.dex (Java_md51390a9bb27ae81984ed2b5a51b13bec9_PostsListViewAdapter_n_1getView__ILandroid_view_View_2Landroid_view_ViewGroup_2+187)
[art] at md51390a9bb27ae81984ed2b5a51b13bec9.PostsListViewAdapter.n_getView(Native method)
[art] at md51390a9bb27ae81984ed2b5a51b13bec9.PostsListViewAdapter.getView(PostsListViewAdapter.java:46)
[art] at android.widget.AbsListView.obtainView(AbsListView.java:2347)
[art] at android.widget.ListView.makeAndAddView(ListView.java:1864)
[art] at android.widget.ListView.fillUp(ListView.java:732)
[art] at android.widget.ListView.fillGap(ListView.java:671)
[art] at android.widget.AbsListView.trackMotionScroll(AbsListView.java:4991)
[art] at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:4539)
[art] at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
[art] at android.view.Choreographer.doCallbacks(Choreographer.java:580)
[art] at android.view.Choreographer.doFrame(Choreographer.java:549)
[art] at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
[art] at android.os.Handler.handleCallback(Handler.java:739)
[art] at android.os.Handler.dispatchMessage(Handler.java:95)
[art] at android.os.Looper.loop(Looper.java:135)
[art] at android.app.ActivityThread.main(ActivityThread.java:5254)
[art] at java.lang.reflect.Method.invoke!(Native method)
[art] at java.lang.reflect.Method.invoke(Method.java:372)
[art] at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
[art] at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
[art] Clamp target GC heap from 111MB to 96MB
[art] Alloc partial concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 1.288ms total 11.770ms
[art] Clamp target GC heap from 111MB to 96MB
[art] Alloc concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 1.475ms total 18.088ms
[art] Forcing collection of SoftReferences for 52B allocation
[art] Clamp target GC heap from 111MB to 96MB
[art] Alloc concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 881us total 16.762ms
[art] Throwing OutOfMemoryError "Failed to allocate a 52 byte allocation with 16 free bytes and 16B until OOM"
[art] Clamp target GC heap from 111MB to 96MB
[art] Alloc partial concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 10.729ms total 22.730ms
[art] Clamp target GC heap from 111MB to 96MB
[art] Alloc concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 650us total 47.875ms
[art] Forcing collection of SoftReferences for 28B allocation
[art] Clamp target GC heap from 111MB to 96MB
[art] Alloc concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 1.204ms total 23.964ms
[art] Throwing OutOfMemoryError "Failed to allocate a 28 byte allocation with 16 free bytes and 16B until OOM" (recursive case)
[art] "main" prio=5 tid=1 Runnable
[art] | group="main" sCount=0 dsCount=0 obj=0x739e6000 self=0xf3c25800
[art] | sysTid=16583 nice=-6 cgrp=default sched=0/0 handle=0xf7711ea0
[art] | state=R schedstat=( 52007888965 3621142086 26132 ) utm=3455 stm=1744 core=3 HZ=100
[art] | stack=0xff04c000-0xff04e000 stackSize=8MB
[art] | held mutexes= "mutator lock"(shared held)
[art] native: #00 pc 00005d03 /system/lib/libbacktrace_libc++.so (UnwindCurrent::Unwind(unsigned int, ucontext*)+83)
[art] native: #01 pc 00003051 /system/lib/libbacktrace_libc++.so (Backtrace::Unwind(unsigned int, ucontext*)+33)
[art] native: #02 pc 003c9b97 /system/lib/libart.so (art::DumpNativeStack(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, int, char const*, art::mirror::ArtMethod*)+135)
[art] native: #03 pc 0038f2c2 /system/lib/libart.so (art::Thread::DumpStack(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const+290)
[art] native: #04 pc 00395bdb /system/lib/libart.so (art::Thread::ThrowOutOfMemoryError(char const*)+459)
[art] native: #05 pc 001f1efb /system/lib/libart.so (art::gc::Heap::ThrowOutOfMemoryError(art::Thread*, unsigned int, art::gc::AllocatorType)+1243)
[art] native: #06 pc 001f5ba5 /system/lib/libart.so (art::gc::Heap::AllocateInternalWithGc(art::Thread*, art::gc::AllocatorType, unsigned int, unsigned int*, unsigned int*, art::mirror::Class**)+2773)
[art] native: #07 pc 0017e1bb /system/lib/libart.so (art::mirror::Class::AllocObject(art::Thread*)+1275)
[art] native: #08 pc 00394dd4 /system/lib/libart.so (art::Thread::ThrowNewWrappedException(art::ThrowLocation const&, char const*, char const*)+820)
[art] native: #09 pc 00395c82 /system/lib/libart.so (art::Thread::ThrowOutOfMemoryError(char const*)+626)
[art] native: #10 pc 001f1efb /system/lib/libart.so (art::gc::Heap::ThrowOutOfMemoryError(art::Thread*, unsigned int, art::gc::AllocatorType)+1243)
[art] native: #11 pc 001f5ba5 /system/lib/libart.so (art::gc::Heap::AllocateInternalWithGc(art::Thread*, art::gc::AllocatorType, unsigned int, unsigned int*, unsigned int*, art::mirror::Class**)+2773)
[art] native: #12 pc 0031eed3 /system/lib/libart.so (art::mirror::String::Alloc(art::Thread*, int)+1955)
[art] native: #13 pc 0031f39d /system/lib/libart.so (art::mirror::String::AllocFromUtf16(art::Thread*, int, unsigned short const*, int)+45)
[art] native: #14 pc 002cb4cb /system/lib/libart.so (art::JNI::NewString(_JNIEnv*, unsigned short const*, int)+363)
[art] native: #15 pc 0010ec4d /system/lib/libart.so (art::CheckJNI::NewString(_JNIEnv*, unsigned short const*, int)+125)
[art] native: #16 pc 00005eb7 (???)
[art] native: #17 pc 000048a2 (???)
[art] native: #18 pc 00004107 (???)
[art] native: #19 pc 00003c8f (???)
[art] native: #20 pc 00003b77 (???)
[art] native: #21 pc 00007bd7 (???)
[art] native: #22 pc 000079fb (???)
[art] native: #23 pc 0000751b (???)
[art] native: #24 pc 00007e74 (???)
[art] native: #25 pc 0002a834 /data/app/Mono.Android.DebugRuntime-1/lib/x86/libmonosgen-32bit-2.0.so (???)
[art] native: #26 pc 001b22cb /data/app/Mono.Android.DebugRuntime-1/lib/x86/libmonosgen-32bit-2.0.so (mono_runtime_invoke+75)
[art] native: #27 pc 000e19bc /data/app/Mono.Android.DebugRuntime-1/lib/x86/libmonosgen-32bit-2.0.so (???)
[art] native: #28 pc 000e2328 /data/app/Mono.Android.DebugRuntime-1/lib/x86/libmonosgen-32bit-2.0.so (???)
[art] native: #29 pc 000e24aa /data/app/Mono.Android.DebugRuntime-1/lib/x86/libmonosgen-32bit-2.0.so (???)
[art] native: #30 pc 000e24aa /data/app/Mono.Android.DebugRuntime-1/lib/x86/libmonosgen-32bit-2.0.so (???)
[art] native: #31 pc 000e24aa /data/app/Mono.Android.DebugRuntime-1/lib/x86/libmonosgen-32bit-2.0.so (???)
[art] native: #32 pc 000e24aa /data/app/Mono.Android.DebugRuntime-1/lib/x86/libmonosgen-32bit-2.0.so (???)
[art] native: #33 pc 000e24aa /data/app/Mono.Android.DebugRuntime-1/lib/x86/libmonosgen-32bit-2.0.so (???)
[art] native: #34 pc 000e24aa /data/app/Mono.Android.DebugRuntime-1/lib/x86/libmonosgen-32bit-2.0.so (???)
[art] native: #35 pc 000e24aa /data/app/Mono.Android.DebugRuntime-1/lib/x86/libmonosgen-32bit-2.0.so (???)
[art] native: #36 pc 000e24aa /data/app/Mono.Android.DebugRuntime-1/lib/x86/libmonosgen-32bit-2.0.so (???)
[art] native: #37 pc 000e24aa /data/app/Mono.Android.DebugRuntime-1/lib/x86/libmonosgen-32bit-2.0.so (???)
[art] native: #38 pc 000e24aa /data/app/Mono.Android.DebugRuntime-1/lib/x86/libmonosgen-32bit-2.0.so (???)
[art] native: #39 pc 000e34f9 /data/app/Mono.Android.DebugRuntime-1/lib/x86/libmonosgen-32bit-2.0.so (???)
[art] native: #40 pc 000f0000 /data/app/Mono.Android.DebugRuntime-1/lib/x86/libmonosgen-32bit-2.0.so (???)
[art] native: #41 pc 00007023 (???)
[art] native: #42 pc 00006fc7 (???)
[art] native: #43 pc 0003134b (???)
[art] native: #44 pc 0000df1f (???)
[art] native: #45 pc 000ad117 /data/dalvik-cache/x86/data@app@com@base.apk@classes.dex (Java_md51390a9bb27ae81984ed2b5a51b13bec9_PostsListViewAdapter_n_1getView__ILandroid_view_View_2Landroid_view_ViewGroup_2+187)
[art] at md51390a9bb27ae81984ed2b5a51b13bec9.PostsListViewAdapter.n_getView(Native method)
[art] at md51390a9bb27ae81984ed2b5a51b13bec9.PostsListViewAdapter.getView(PostsListViewAdapter.java:46)
[art] at android.widget.AbsListView.obtainView(AbsListView.java:2347)
[art] at android.widget.ListView.makeAndAddView(ListView.java:1864)
[art] at android.widget.ListView.fillUp(ListView.java:732)
[art] at android.widget.ListView.fillGap(ListView.java:671)
[art] at android.widget.AbsListView.trackMotionScroll(AbsListView.java:4991)
[art] at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:4539)
[art] at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
[art] at android.view.Choreographer.doCallbacks(Choreographer.java:580)
[art] at android.view.Choreographer.doFrame(Choreographer.java:549)
[art] at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
[art] at android.os.Handler.handleCallback(Handler.java:739)
[art] at android.os.Handler.dispatchMessage(Handler.java:95)
[art] at android.os.Looper.loop(Looper.java:135)
[art] at android.app.ActivityThread.main(ActivityThread.java:5254)
[art] at java.lang.reflect.Method.invoke!(Native method)
[art] at java.lang.reflect.Method.invoke(Method.java:372)
[art] at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
[art] at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Thread finished: <Thread Pool> #14
[Mono] [0xeecaef80] worker finishing
Thread finished: <Thread Pool> #21
[Mono] [0xd92e8500] worker finishing
Thread finished: <Thread Pool> #19
[Mono] [0xd92e8280] worker finishing
Thread finished: <Thread Pool> #23
Thread finished: <Thread Pool> #9
[Mono] [0xdace7600] worker finishing
public async Task SetImage (Activity activity, ImageView view, string url, string imagesDirectory)
{
Bitmap bitmap = (Bitmap)Get (url);
if (bitmap == null) {
string file = System.IO.Path.Combine (imagesDirectory, Helper.ImageNameFromUrl(url));
if (System.IO.File.Exists (file)) {
BitmapFactory.Options options = new BitmapFactory.Options ();
options.InPreferredConfig = Bitmap.Config.Argb8888;
bitmap = BitmapFactory.DecodeFile (file, options);
} else {
bitmap = await WebWorker.DownloadImage (url);
SdWorker.SaveBitmap (bitmap, file);
}
Console.WriteLine ("no cache for item");
Put (url, bitmap);
} else {
Console.WriteLine (url + " fetched from cache");
}
activity.RunOnUiThread (() => {
view.SetImageBitmap (bitmap);
});
}
答案 0 :(得分:1)
首先,我想了解一下实现ViewHolder模式。您可以在此处详细了解https://blog.xamarin.com/creating-highly-performant-smooth-scrolling-android-listviews/ 基本上,通过重复使用listview中的单元格,有助于加快列表视图的速度
一旦完成,我将从GetView中删除任何异步操作。每次单元格即将可见时,都会调用GetView。因此,UI线程上的任何计算繁重操作都会使事情变得很慢。
最后,我会尝试手动处理所有图像。通过孩子们循环。
public override View GetView (int position, View convertView, ViewGroup parent)
{
MyViewHolder holder;
var view = convertView;
if(view != null)
holder = view.Tag as MyViewHolder;
if (holder == null) {
holder = new MyViewHolder ();
view = LayoutInflater.From (_context).Inflate (Resource.Layout.PostsListItem, null);
holder.MediaLinear = view.FindViewById<LinearLayout> (Resource.Id.post_media);
view.Tag = holder;
}
LoadViewHolderImages(holder);
return view;
}
async Task LoadViewHolderImages(MyViewHolder holder)
{
CleanupImageViewHolder(holder);
var ats = await DBWorker.Instance.Connection.Table<Core.Local.Attachment> ().Where (...).ToListAsync();
foreach (var att in ats {
var im = new ImageView (_context); //exception here
await _memoryCache.SetImage (_context, im, att.url, MainActivity.TempFolder);
mediaLinear.AddView (im);
}
}
void CleanupImageViewHolder(MyViewHolder holder)
{
// Lets Manually dispose of all children images
for (int i = 0; i < holder.MediaLinear.ChildCount; i++) {
var view = holder.MediaLinear.GetChildAt (i) as ImageView;
if (view != null) {
view.Dispose();
}
}
holder.MediaLinear.RemoveAllViewsInLayout ();
}