我有一个派生自UIControl的类MyObject,我还有一个List,它在MyObject类型上保存了几个对象。
在调用base.ViewDidLoad()之前,所有这些对象都作为SubViews添加到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.
=================================================================
答案 0 :(得分:2)
从这里开始:
at MonoTouch.UIKit.UIView.set_Frame (System.Drawing.RectangleF) [0x00021] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIView.g.cs:1179
看起来你正在为已经被释放的视图设置Frame。
答案 1 :(得分:1)
创建视图时,将其标记设置为333,即 要处置视图: MyCreatedView.ViewWithTag(333).RemoveFromSuperview();
其中-MyCreatedView-是您想要摆脱的视图的父视图。