Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This issue is discussed at some length in <a href="https://bugzilla.xamarin.com/show_bug.cgi?id=1086" rel="nofollow">Bug 1086</a></p> <blockquote> <p>Well, this is a ref-counting/ownership problem:</p> <p>You create a new MyObject instance in your MyDataSource.GetObjectValue(), then return it to native code, without keeping a reference to it. After returning, you do not own that object anymore, but the managed garbage collector does not know that.</p> <p>Simply store the objects in a list, like this:</p> <pre><code>List&lt;MyObject&gt; list; public MyDataSource () { list = new List&lt;MyObject&gt; (); for (int i = 0; i &lt; 10; i++) { list.Add (new MyObject { Text = "My Row " + i }); } } public override NSObject GetObjectValue (NSTableView tableView, NSTableColumn tableColumn, int row) { return list [row]; } public override int GetRowCount (NSTableView tableView) { return list.Count; } </code></pre> <p>However, this does not solve your copyWithZone: problem. Here, storing the cloned objects locally is not an option, this would leak a lot of memory quickly. Instead, you need to call retain on the cloned object. Unfortunately, NSObject.Retain() is internal in MonoMac.dll, but you can just simply do it like this:</p> <pre><code>static IntPtr selRetain = Selector.GetHandle ("retain"); [Export("copyWithZone:")] public NSObject CopyWithZone (IntPtr zone) { var cloned = new MyObject { Text = this.Text }; Messaging.void_objc_msgSend (cloned.Handle, selRetain); return cloned; } </code></pre> </blockquote> <p>From memory the code in the last example isn't complete, you have to combine the two examples and track the new <code>MyObject</code> in a list (or some other collection) as well.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload