简体   繁体   English

没有StackTrace或日志的Monotouch应用程序崩溃(从不调用析构函数)

[英]Monotouch Application Crashing with no StackTrace or logs (Destructor never called)

My MonoTouch app keeps crashing and I do not know what to do. 我的MonoTouch应用程序不断崩溃,我不知道该怎么做。 At this point, I feel like I have tried everything. 在这一点上,我觉得我已经尝试了一切。 I have a RootViewController, which transitions to an endless number of vewcontrollers. 我有一个RootViewController,它转换为无数的vewcontrollers。 Each time a trasnition takes place, I manually call dispose on the previous ViewController and display the new one. 每次进行传输时,我都会在之前的ViewController上手动调用dispose并显示新的。

It feels like a memory leak to me, as the application crashes about 20-40 ViewControllers in and definately gets more sluggish before hand. 感觉就像一个内存泄漏给我,因为应用程序崩溃了大约20-40个ViewControllers并且肯定会在手前变得更加迟钝。

  1. How can I view memory usage of my MonoTouch application on the device? 如何在设备上查看MonoTouch应用程序的内存使用情况? (Not crashing in the simulator) (不会在模拟器中崩溃)

  2. Any more diagnostic ways to figure out why it is crashing? 任何更多的诊断方法来弄清楚它崩溃的原因?

Any help would be grateful. 任何帮助将不胜感激。

UPDATE I have added the following to my VC. 更新我已将以下内容添加到我的VC中。

~TargetPromptController(){
    Console.WriteLine("TargetPromptController Released from memory!");
 }

And it never gets called. 它永远不会被称为。

Be sure to dispose object that are not needed. 务必处置不需要的对象。 Even though mono touch does some of this for you, I find it better to do this in my code. 即使单声道触摸为你做了一些,我觉得在我的代码中做到这一点更好。 Always force GC during extensive routines in loops where code is generating a lot of disposable objects. 在循环中的大量例程期间始终强制GC,其中代码生成大量一次性对象。 PS I wouldn't call Monotouch immature. PS我不会称Monotouch不成熟。 The platform rocks! 平台摇滚!

The C# GC class can give you an indication of the total amount of memory in use, but is very inaccurate and mostly wrong. C#GC类可以为您提供正在使用的内存总量的指示,但是非常不准确且大多数都是错误的。 It can however tell you if memory usage is increasing, decreasing or steady. 但是,它可以告诉您内存使用量是增加,减少还是稳定。 Generally, I've had more problems when doing GC.Collect than I've had without. 一般来说,我在做GC.Collect时遇到的问题比我没有的要多。 So my general suggestion is to not use that method. 所以我的一般建议是不要使用那种方法。

You can debug on the device using the techniques described here . 您可以使用此处描述的技术在设备上进行调试。 However, I've had problem with that and recommend contacting Monotouch if you run into problems with device debugging. 但是,我遇到了问题,如果您遇到设备调试问题,建议您联系Monotouch。

Your problem is probably that Monotouch is keeping the ViewController in memory, despite your call to Dispose. 您的问题可能是Monotouch将ViewController保留在内存中,尽管您调用了Dispose。 Create a property that is of type List and keep your VCs there. 创建一个List类型的属性,并保存您的VC。 This can make it easier for MonoTouch to detect and collect unused VCs. 这可以使MonoTouch更容易检测和收集未使用的VC。 Also, remove the VCs contents from as much as possible before releasing it from the collection. 此外,在从集合中释放VC之前,尽可能地删除VC内容。 I've seen Monotouch keeping references to child objects of whose parent object I've disposed of. 我已经看到Monotouch保留对我已经处理过的父对象的子对象的引用。

All in all, Monotouch is not a mature product and you will have to get used to contacting their support team. 总而言之,Monotouch不是一个成熟的产品,您将不得不习惯联系他们的支持团队。 And please , post your solution here so that we all can learn! 在这里发布您的解决方案,以便我们都可以学习! :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM