I'm hitting a crash when receiving memory warnings in some situations. In 
one view controller (A) we are handling the memory warning by calling 
Dispose() on another view controller (B) which is no longer necessary. 
Unfortunately, something later on during the process of the (native) 
memory warning handling code is trying to call a method in view controller 
B, and it's trying to construct a managed object to do so. This causes an 
exception because I don't have a constructor which takes an IntPtr so the 
runtime can't construct the managed object.

I know that if implementing the IntPtr constructor the crash doesn't 
occur. I also know that it goes away if I remove the call to Dispose, but 
I don't think that's a guaranteed fix since the object could still be 
GCed. I'm looking for the "right" fix, but I have several unanswered 
questions about what is going on that I need to find an answer to in order 
to find it.

The first question is what method is being called on view controller B, 
and why is it wanting a managed object to call that method? I don't have 
an override for DidReceiveMemoryWarning or ViewDidUnload. In fact, the 
only override in that view controller (which inherits directly from 
UITableViewController) is ViewDidLoad. The exception tells me "Selector 
invoked from objective-c on a managed object (0xB9E72D0) that has been 
GC'ed", but it won't tell me which selector was invoked. In a simpler test 
case that I created I could only reproduce the crash if I overrode either 
DidReceiveMemoryWarning or ViewDidUnload, but in my full application I get 
the crash even though I haven't implemented either. I don't understand 
why. Is there a trick to figuring out which method is being invoked when 
this exception occurs?

The second question is what are the rules for when we are expected to 
implement the IntPtr constructor for classes that inherit from NSObject? I 
don't want to blindly add it to every class, especially since in some 
cases it probably can't be implemented in a sane way at all (the Dispose 
method might have released resources that you can't get back without 
arguments from a real constructor). Is there some rule for this? Does my 
situation fit that rule?

Thanks.
--
Adam Kemp
[email protected]
(512) 683-6058
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to