我有一个图片丰富的主页(20到300KB的在线资料)。我有另一页在重构的圆圈中显示联系人及其图像(20KB到300KB)。在联系页面上,它是一个包含3个片段的选项卡。当我从fragement 1切换到2到3并反复重复时,我的应用程序停止工作并抛出错误。
此外,当应用程序启动主页并滚动浏览源时,当我移动到下一个活动(联系页面)时,它会在到达联系页面之前滞后一段时间(几秒钟之后,它会崩溃) 。查看我的日志,这就是我所看到的,我一直在努力找到自己的方式。
在我的所有活动中,我都包括GC.Collect()
以获得更多空间用于其他活动,但仍然不适合我。
我顺便将应用程序中的java堆大小增加到1G。我还在我的联系页面上处理了位图。
知道是什么导致了这个问题?
异常
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_call_nonvirtual_object_method'.
[Mono] Probing 'java_interop_jnienv_call_nonvirtual_object_method'.
[Mono] Found as 'java_interop_jnienv_call_nonvirtual_object_method'.
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_call_void_method_a'.
[Mono] Probing 'java_interop_jnienv_call_void_method_a'.
[Mono] Found as 'java_interop_jnienv_call_void_method_a'.
[Mono] Assembly Ref addref Xamarin.Android.Support.Design[0x7cf85210] -> Xamarin.Android.Support.Core.UI[0x7ce7c4a8]: 4
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_new_local_ref'.
[Mono] Probing 'java_interop_jnienv_new_local_ref'.
[Mono] Found as 'java_interop_jnienv_new_local_ref'.
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_call_boolean_method_a'.
[Mono] Probing 'java_interop_jnienv_call_boolean_method_a'.
[Mono] Found as 'java_interop_jnienv_call_boolean_method_a'.
[Adreno-EGL] <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: ()
[Adreno-EGL] OpenGL ES Shader Compiler Version: E031.24.00.07
[Adreno-EGL] Build Date: 01/22/14 Wed
[Adreno-EGL] Local Branch: base_au149_adreno_au169_patches
[Adreno-EGL] Remote Branch:
[Adreno-EGL] Local Patches:
[Adreno-EGL] Reconstruct Branch:
[OpenGLRenderer] Enabling debug mode 0
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_call_int_method'.
[Mono] Probing 'java_interop_jnienv_call_int_method'.
[Mono] Found as 'java_interop_jnienv_call_int_method'.
[Mono] Assembly Ref addref Xamarin.Android.Support.v7.AppCompat[0x7d0e4ac0] -> Xamarin.Android.Support.Compat[0x7bbff618]: 4
[dalvikvm-heap] Grow heap (frag case) to 43.690MB for 14449048-byte allocation
[RecyclerView] No adapter attached; skipping layout
[RecyclerView] No adapter attached; skipping layout
[RecyclerView] No adapter attached; skipping layout
[RecyclerView] No adapter attached; skipping layout
[Mono] GC_TAR_BRIDGE bridges 24 objects 34 opaque 8 colors 24 colors-bridged 24 colors-visible 24 xref 6 cache-hit 0 cache-semihit 0 cache-miss 0 setup 0.05ms tarjan 0.10ms scc-setup 0.05ms gather-xref 0.00ms xref-setup 0.00ms cleanup 0.04ms
[Mono] GC_BRIDGE: Complete, was running for 25.34ms
[Mono] GC_MAJOR_SWEEP: major size: 784K in use: 199K
[Mono] GC_MAJOR: (user request) time 3.53ms, stw 3.72ms los size: 1024K in use: 8K
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_call_void_method'.
[Mono] Probing 'java_interop_jnienv_call_void_method'.
[Mono] Found as 'java_interop_jnienv_call_void_method'.
[Mono] Assembly Ref addref Xamarin.Android.Support.Fragment[0x7cfeb058] -> Xamarin.Android.Support.Core.UI[0x7ce7c4a8]: 5
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_get_field_id'.
[Mono] Probing 'java_interop_jnienv_get_field_id'.
[Mono] Found as 'java_interop_jnienv_get_field_id'.
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_get_int_field'.
[Mono] Probing 'java_interop_jnienv_get_int_field'.
[Mono] Found as 'java_interop_jnienv_get_int_field'.
[Mono] Assembly Ref addref Xamarin.Android.Support.v7.RecyclerView[0x7d4d3508] -> Xamarin.Android.Support.Core.UI[0x7ce7c4a8]: 6
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_get_object_array_element'.
[Mono] Probing 'java_interop_jnienv_get_object_array_element'.
[Mono] Found as 'java_interop_jnienv_get_object_array_element'.
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_set_boolean_field'.
[Mono] Probing 'java_interop_jnienv_set_boolean_field'.
[Mono] Found as 'java_interop_jnienv_set_boolean_field'.
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_set_int_field'.
[Mono] Probing 'java_interop_jnienv_set_int_field'.
[Mono] Found as 'java_interop_jnienv_set_int_field'.
Thread started: <Thread Pool> #2
Thread started: <Thread Pool> #3
[Mono] [0x853813e8] worker starting
Thread started: <Thread Pool> #4
Thread started: <Thread Pool> #5
[Mono] [0x85e6fb88] worker starting
[Mono] [0x85e6ffd8] worker starting
Thread started: <Thread Pool> #6
[Mono] [0x85e7bcf8] worker starting
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_get_static_field_id'.
[Mono] Probing 'java_interop_jnienv_get_static_field_id'.
[Mono] Found as 'java_interop_jnienv_get_static_field_id'.
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_get_static_object_field'.
[Mono] Probing 'java_interop_jnienv_get_static_object_field'.
[Mono] Found as 'java_interop_jnienv_get_static_object_field'.
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_call_nonvirtual_boolean_method_a'.
[Mono] Probing 'java_interop_jnienv_call_nonvirtual_boolean_method_a'.
[Mono] Found as 'java_interop_jnienv_call_nonvirtual_boolean_method_a'.
[Mono] [0x85e6ffd8] hill climbing, change max number of threads 4
[Choreographer] Skipped 34 frames! The application may be doing too much work on its main thread.
[Mono] [0x85e6ffd8] hill climbing, change max number of threads 5
Thread started: <Thread Pool> #7
Thread started: <Thread Pool> #8
[Mono] [0x85de0cb8] worker starting
[Mono] [0x85e19438] worker starting
[dalvikvm-heap] Clamp target GC heap from 134.009MB to 128.000MB
[dalvikvm-heap] Clamp target GC heap from 138.888MB to 128.000MB
[dalvikvm-heap] Forcing collection of SoftReferences for 1575952-byte allocation
[dalvikvm-heap] Clamp target GC heap from 142.888MB to 128.000MB
[dalvikvm-heap] Out of memory on a 1575952-byte allocation.
[skia] --- allocation failed for scaled bitmap
[dalvikvm-heap] Clamp target GC heap from 142.888MB to 128.000MB
[dalvikvm-heap] Forcing collection of SoftReferences for 921616-byte allocation
[dalvikvm-heap] Clamp target GC heap from 142.888MB to 128.000MB
[dalvikvm-heap] Out of memory on a 921616-byte allocation.
[skia] --- allocation failed for scaled bitmap
[Mono] Image addref System.Runtime.Serialization[0x82d6fad0] -> System.Runtime.Serialization.dll[0x82d6ece8]: 2
[Mono] Prepared to set up assembly 'System.Runtime.Serialization' (System.Runtime.Serialization.dll)
[Mono] Assembly System.Runtime.Serialization[0x82d6fad0] added to domain RootDomain, ref_count=1
[Mono] AOT: image 'System.Runtime.Serialization.dll.so' not found: dlopen failed: library "/data/app-lib/com.companyname.peaceapp.peaceapp-115/libaot-System.Runtime.Serialization.dll.so" not found
[Mono] AOT: image '/usr/local/lib/mono/aot-cache/arm/System.Runtime.Serialization.dll.so' not found: dlopen failed: library "/data/app-lib/com.companyname.peaceapp.peaceapp-115/libaot-System.Runtime.Serialization.dll.so" not found
[Mono] Config attempting to parse: 'System.Runtime.Serialization.dll.config'.
[Mono] Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Runtime.Serialization/System.Runtime.Serialization.config'.
[Mono] Assembly Ref addref Mono.Android[0x7d63cb60] -> System.Runtime.Serialization[0x82d6fad0]: 2
[Mono] Assembly Ref addref System.Runtime.Serialization[0x82d6fad0] -> mscorlib[0x72798a08]: 31
Loaded assembly: System.Runtime.Serialization.dll [External]
Thread finished: <Thread Pool> #5
[Mono] [0x85e6ffd8] worker finishing
答案 0 :(得分:0)
您可以在清单中或通过LargeHeap
子类
Application
android:largeHeap
[Application(LargeHeap = true)]
public class XamarinAndroidApp : Application
{
~~~~
}
这是只是一个请求,根据设备的不同,您可能会或可能不会获得增加的Java / Dalvik堆,并且您的应用不依赖于获取增加的堆大小
大多数应用程序不应该需要这个,而应该专注于减少整体内存使用量以提高性能。启用此功能也不能保证可用内存的固定增加,因为某些设备受其总可用内存的限制。
正如您的错误所示,您的Java堆在该设备上被限制为128MB
,并且这是一个适中的堆大小,因为它们在较旧的低端设备和较新的高端设备上可以低至16MB可以达到512MB(在某些设备上更多)。但请注意,每个设备的堆大小不是变量,并且是硬连线的(/system/build.prop
),除了让您的应用请求LargeHeap
之外,您无法控制它。
Fragment
,View
等方式保留对位图的引用,以致无法收集和发布它们LruCache
)来管理在任何给定时间内在内存中保留了多少Bitmap