简体   繁体   中英

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

My MonoTouch app keeps crashing and I do not know what to do. At this point, I feel like I have tried everything. I have a RootViewController, which transitions to an endless number of vewcontrollers. Each time a trasnition takes place, I manually call dispose on the previous ViewController and display the new one.

It feels like a memory leak to me, as the application crashes about 20-40 ViewControllers in and definately gets more sluggish before hand.

  1. How can I view memory usage of my MonoTouch application on the device? (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.

~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. PS I wouldn't call Monotouch immature. 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. 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. 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.

Your problem is probably that Monotouch is keeping the ViewController in memory, despite your call to Dispose. Create a property that is of type List and keep your VCs there. This can make it easier for MonoTouch to detect and collect unused VCs. Also, remove the VCs contents from as much as possible before releasing it from the collection. I've seen Monotouch keeping references to child objects of whose parent object I've disposed of.

All in all, Monotouch is not a mature product and you will have to get used to contacting their support team. And please , post your solution here so that we all can learn! :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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