D/Objective-C 64bit
Jacob Carlborg via Digitalmars-d-announce
digitalmars-d-announce at puremagic.com
Tue Oct 28 12:58:14 PDT 2014
On 2014-10-27 19:03, Christian Schneider wrote:
> Can somebody with a greater d-objc knowledge have a look at this example
> project and tell this naive D-noob what he is missing?
>
> https://github.com/DiveFramework/DiveFramework/tree/master/Examples/Tableview
>
>
> I am pretty sure that it has something to do with memory management and
> ARC. First it all starts up right, but then a delegate method get's
> called in the wild and some memory segmentation is occurring calling
> objectAtIndex, which is called on very different objects on multiple
> runs, and I cannot get any closer to the real issue.
>
> NSMutableArray _applications ;
>
> is the main culprit, in this I am trying to put some NSObject subclass
> objects. I have to admit that my mind is all Objective-C and very little
> D yet, and probably the solution is very simple. What I have further
> found is, that the crash occurs in relation to the visible table cells.
> As soon as a view for an invisible cell is requested, the seg fault
> occurs. I am trying to elaborate a TableView example using View based
> cells.
>
> To compile the program, you only need to execute "dub" in the
> Examples/Tableview directory, of course assuming you have the latest
> d-objc branch dmd installed and dub (and Xcode, I am using 5.1.1 but 6
> should work just as well).
I tried running your code and could observe the behavior. Although I
have not been able to figure you why it behaves like this. In general
there are a couple of things to think of and watch out for when
interfacing between D and Objective-C :
* The D compiler does not support any form of ARC, it's back to using
retain/release
* When allocating memory with the GC in D and passing it to Objective-C
(or C for that matter) you have to make sure there is still a root
pointing to the memory. This can either be a variable that is still in
scope or by explicitly adding a new root by calling core.GC.addRoot.
I don't know if any of the above is the actual problem, but it could be.
I would recommend trying to contact Michel Fortin how original
implemented D/Objective-C.
BTW, There is a tool, DStep [1], that can automatically generate
bindings for Objective-C code.
[1] https://github.com/jacob-carlborg/dstep
--
/Jacob Carlborg
More information about the Digitalmars-d-announce
mailing list