[MonoTouch] Still IntPtr Constructor issues

René Ruppert rene.ruppert at googlemail.com
Thu Dec 8 11:40:12 EST 2011


Thanks for this detailed answer. Is there a list of cases that show when I will have to keep explicit refs? You should know best where things can go wrong.  

Please announce once you have that document ready that explains the changes. Miguel said you are working on a concept that will fix all of these problems. Is this the same topic?

As for releasing the references: if the view that is using the cells is managed by a controller, is my assumption correct that I do not need to release them explicitly if I hold them in the view itself? I mean, if the view is unloaded it should get GC'd together with the cells. 

Grüße, René

Am 08.12.2011 um 16:56 schrieb Rolf Bjarne Kvinge <rolf at xamarin.com>:

> On Thu, Dec 8, 2011 at 1:52 AM, Rene Ruppert <rene.ruppert at googlemail.com> wrote:
> But isn't that then,like Miguel said, an issue of Monotouch? Shouldn't it keep a reference?
> I have not seen a single MT example so far tat keeps explicit references to table view cells. Are they all wrong?
> 
> It's actually quite a tricky subject, we've tried a lot of possible solutions and we've come to the conclusion that it's virtually impossible to make it perfect (which is that managed code should not need to hold objects alive manually and at the same time no objects should be leaked). We have improved some scenarios (included in the current v5.1.1 beta, but it has to be enabled manually), and we're working on documentation explaining exactly what has been improved.
> 
> Returning to your particular problem: in theory it should work if you subclass UITableViewCell (which you do) - in which case the object is kept alive while native code has a ref. Unfortunately objc might not keep a ref in all cases (for instance look at assign setter semantics here: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocProperties.html#//apple_ref/doc/uid/TP30001163-CH17-SW2), which I suspect is what's happening to you. It is however hard to find the exact cause without a sample we can run ourselves.
> 
> Keeping an explicit ref to table view cells is a pretty easy workaround (and it doesn't suffer from the undefined behavior adding the IntPtr ctor would have). The problem is of course to know when to remove the explicit ref - but in my experience you don't end up with that many table view cell instances if you reuse them (and just release the explicit ref when the corresponding view is unloaded).
> 
> I hope this helps,
> Rolf
>  
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/monotouch/attachments/20111208/9e64205f/attachment.html 


More information about the MonoTouch mailing list