1

我有一个从 UIControl 派生的名为 MyObject 的类,我还有一个包含多个 MyObject 类型对象的 List。

在调用 base.ViewDidLoad() 之前,所有这些对象都作为子视图添加到 UIViewController 的 ViewDidLoad 重写方法中;(我不知道这是否重要)。

问题是在某些时期我想删除几个对象,因为我不再需要它们了。以下是我采取的步骤: - 首先,我从我的通用列表集合中删除该对象 - 然后我使用 RemoveFromSuperview() 方法将其从视图中删除。此时一切正常,但我也想从内存中删除它,因为我不再需要它而且我还需要添加更多对象,所以我必须释放一些内存。所以我在那个对象上调用 Dispose() 方法。

一旦我这样做,我就会得到一个令人讨厌的例外:

Stacktrace:

at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging.void_objc_msgSendSuper_RectangleF (intptr,intptr,System.Drawing.RectangleF) <IL 0x00025, 0xffffffff>
at MonoTouch.UIKit.UIView.set_Frame (System.Drawing.RectangleF) [0x00021] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIView.g.cs:1179
at BubbleBuster.Lib.UI.Gameplay.Bubble.Update (System.Drawing.RectangleF) [0x001a2] in /Development/Helix/iOS/BubbleBuster/BubbleBusterSolution/BubbleBusterApp/Lib/UI/Gameplay/Bubble.cs:141
at BubbleBuster.Lib.UI.Gameplay.BubbleCollection/<Update>c__AnonStorey2.<>m__4 (BubbleBuster.Lib.UI.Gameplay.Bubble) [0x00014] in /Development/Helix/iOS/BubbleBuster/BubbleBusterSolution/BubbleBusterApp/Lib/UI/Gameplay/BubbleCollection.cs:21
at System.Collections.Generic.List`1.ForEach (System.Action`1<T>) [0x00018] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Collections.Generic/List.cs:360
at BubbleBuster.Lib.UI.Gameplay.BubbleCollection.Update (System.Drawing.RectangleF) [0x00014] in /Development/Helix/iOS/BubbleBuster/BubbleBusterSolution/BubbleBusterApp/Lib/UI/Gameplay/BubbleCollection.cs:19
at BubbleBuster.Lib.UI.Screens.WelcomeScreen.<UpdateTime_Elapsed>m__1 () [0x00000] in /Development/Helix/iOS/BubbleBuster/BubbleBusterSolution/BubbleBusterApp/Lib/UI/Screens/WelcomeScreen.cs:44
at MonoTouch.Foundation.NSActionDispatcher.Apply () [0x00000] in /Developer/MonoTouch/Source/monotouch/src/shared/Foundation/NSAction.cs:48
at (wrapper runtime-invoke) object.runtime_invoke_void__this__ (object,intptr,intptr,intptr) <IL 0x0004e, 0xffffffff>
at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <IL 0x0009f, 0xffffffff>

Thread started: 
at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x00042] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29
at BubbleBuster.Application.Main (string[]) [0x00000] in /Development/Helix/iOS/BubbleBuster/BubbleBusterSolution/BubbleBusterApp/Main.cs:17
at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>

Native stacktrace:

0   BubbleBusterApp                     0x0009094c mono_handle_native_sigsegv + 284
1   BubbleBusterApp                     0x00005cd8 mono_sigsegv_signal_handler + 248
2   libsystem_c.dylib                   0x9923959b _sigtramp + 43
3   ???                                 0xffffffff 0x0 + 4294967295
4   ???                                 0x0e2662b8 0x0 + 237396664
5   ???                                 0x0e2661dc 0x0 + 237396444
6   ???                                 0x0e2651c6 0x0 + 237392326
7   ???                                 0x0e269920 0x0 + 237410592
8   ???                                 0x0e24f8e2 0x0 + 237304034
9   ???                                 0x0e2697e4 0x0 + 237410276
10  ???                                 0x0e269678 0x0 + 237409912
11  ???                                 0x0e2695e0 0x0 + 237409760
12  ???                                 0x09fe9a90 0x0 + 167680656
13  BubbleBusterApp                     0x0000a042 mono_jit_runtime_invoke + 722
14  BubbleBusterApp                     0x00169f4e mono_runtime_invoke + 126
15  BubbleBusterApp                     0x00206748 monotouch_trampoline + 3416
16  CoreFoundation                      0x011d6e42 -[NSObject performSelector:withObject:] + 66
17  Foundation                          0x017509df __NSThreadPerformPerform + 254
18  CoreFoundation                      0x011a994f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
19  CoreFoundation                      0x0110cb43 __CFRunLoopDoSources0 + 243
20  CoreFoundation                      0x0110c424 __CFRunLoopRun + 1012
21  CoreFoundation                      0x0110bd84 CFRunLoopRunSpecific + 212
22  CoreFoundation                      0x0110bc9b CFRunLoopRunInMode + 123
23  GraphicsServices                    0x047c47d8 GSEventRunModal + 190
24  GraphicsServices                    0x047c488a GSEventRun + 103
25  UIKit                               0x02258626 UIApplicationMain + 1163
26  ???                                 0x0d7c4a05 0x0 + 226249221
27  ???                                 0x0d53cf18 0x0 + 223596312
28  ???                                 0x0d53cc10 0x0 + 223595536
29  ???                                 0x0d53cd66 0x0 + 223595878
30  BubbleBusterApp                     0x0000a042 mono_jit_runtime_invoke + 722
31  BubbleBusterApp                     0x00169f4e mono_runtime_invoke + 126
32  BubbleBusterApp                     0x0016e034 mono_runtime_exec_main + 420
33  BubbleBusterApp                     0x00173455 mono_runtime_run_main + 725
34  BubbleBusterApp                     0x00067245 mono_jit_exec + 149
35  BubbleBusterApp                     0x002116a5 main + 2837
36  BubbleBusterApp                     0x00003095 start + 53

=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================
4

2 回答 2

2

从这里:

at MonoTouch.UIKit.UIView.set_Frame (System.Drawing.RectangleF) [0x00021] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIView.g.cs:1179

看起来您正在将 Frame 设置在已被释放的视图上。

于 2012-06-28T09:02:12.170 回答
1

创建视图时,将其标记设置为 333 即处置视图: MyCreatedView.ViewWithTag(333).RemoveFromSuperview();

其中 -MyCreatedView- 是您要删除的视图的父视图。

于 2012-08-22T21:37:26.703 回答