2

我有一个关于单点触控应用程序内存限制的问题。

我试图用一个非常简单的应用程序来强调我的 iPad 内存,该应用程序将 1MB 数组分配到一个列表中。在每个循环上,我都会显示循环数。我注意到我的应用程序崩溃了大约 130 MB 分配。

我的代码:

List<byte[]> arrays = new List<byte[]>();
try
{
    for (int i = 0; i < 1323; i++)
    {
        arrays.Add(new byte[1024 * 1024]);
        Console.WriteLine("RAM: " + (i + 1) + " Mo");
    }
}
catch { }

我不明白为什么在 iPad 3 或 iPad 4 上,我的应用程序崩溃了大约 130MB,并显示以下消息:

本机堆栈跟踪:

0   TestMemory                          0x002687f9 mono_handle_native_sigsegv + 244
1   TestMemory                          0x00295d75 sigabrt_signal_handler + 112
2   libsystem_c.dylib                   0x35a75e93 _sigtramp + 42
3   libsystem_c.dylib                   0x35a6c123 pthread_kill + 58
4   libsystem_c.dylib                   0x35aa8973 abort + 94
5   TestMemory                          0x0026353d GC_expand_hp_inner + 0
6   TestMemory                          0x00263637 GC_expand_hp_inner + 250
7   TestMemory                          0x00263aed GC_collect_or_expand + 128
8   TestMemory                          0x00265d99 GC_alloc_large + 96
9   TestMemory                          0x00265fe9 GC_generic_malloc + 180
10  TestMemory                          0x00266185 GC_malloc_atomic + 112
11  TestMemory                          0x0028c011 mono_array_new_specific + 124
12  TestMemory                          0x00172e04 wrapper_managed_to_native_object___icall_wrapper_mono_array_new_specific_intptr_int + 68
13  TestMemory                          0x0007305c MonoTouch_UIKit_UIControlEventProxy_Activated + 68
14  TestMemory                          0x0016df50 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 200
15  TestMemory                          0x002314e3 mono_jit_runtime_invoke + 1054
16  TestMemory                          0x0028c8c3 mono_runtime_invoke + 90
17  TestMemory                          0x0022b6f7 native_to_managed_trampoline_MonoTouch_UIKit_UIControlEventProxy_Activated + 178
18  UIKit                               0x3ace40a5 <redacted> + 72
19  UIKit                               0x3ace4057 <redacted> + 30
20  UIKit                               0x3ace4035 <redacted> + 44
21  UIKit                               0x3ace38eb <redacted> + 502
22  UIKit                               0x3ace357b <redacted> + 242
23  UIKit                               0x3ac0c523 <redacted> + 318
24  UIKit                               0x3abf9801 <redacted> + 380
25  UIKit                               0x3abf911b <redacted> + 6154
26  GraphicsServices                    0x3637c5a3 <redacted> + 590
27  GraphicsServices                    0x3637c1d3 <redacted> + 34
28  CoreFoundation                      0x38856173 <redacted> + 34
29  CoreFoundation                      0x38856117 <redacted> + 138
30  CoreFoundation                      0x38854f99 <redacted> + 1384
31  CoreFoundation                      0x387c7ebd CFRunLoopRunSpecific + 356
32  CoreFoundation                      0x387c7d49 CFRunLoopRunInMode + 104
33  GraphicsServices                    0x3637b2eb GSEventRunModal + 74
34  UIKit                               0x3ac4d2f9 UIApplicationMain + 1120
35  TestMemory                          0x0008b3c4 wrapper_managed_to_native_MonoTouch_UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr + 240
36  TestMemory                          0x00219bf0 TestMemory_Application_Main_string__ + 152
37  TestMemory                          0x0016df50 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 200
38  TestMemory                          0x002314e3 mono_jit_runtime_invoke + 1054
39  TestMemory                          0x0028c8c3 mono_runtime_invoke + 90
40  TestMemory                          0x0028f3a7 mono_runtime_exec_main + 306
41  TestMemory                          0x0029262b mono_runtime_run_main + 482
42  TestMemory                          0x00242ecf mono_jit_exec + 94
43  TestMemory                          0x002cce3c main + 2220
44  TestMemory                          0x00002028 start + 40
4

1 回答 1

2

你崩溃是因为你用完了 iOS 愿意给你的所有内存。这不是 MonoTouch 的限制,而是 iOS 的限制。

于 2013-06-26T12:02:30.133 回答