Djinni - pointers and circular links between C ++ and fast / objective C / java

I have two djinni interfaces, one of which will be implemented in Swift / Object C / java SwiftObjand one of them will be implemented in C ++ CPPObj.

SwiftObj = interface +o +j {
    someSwiftMethod();
}

CPPObj = interface +c {
    static create(swiftObj: SwiftObj): CPPObj;
    someCPPMethod();
}

Both of them have a pointer to each other, so they SwiftObjcan call someCPPMethod() CPPObjand vice versa: they CPPObjcan call someSwiftMethod()from SwiftObj:

Quickly:

  • class variable: var myCPPObj: SwiftObj!
  • creature: myCPPObj = MyCPPObj.create(self)
  • using: myCPPObj.someCPPMethod()

In C ++:

  • class variable: shared_ptr<SwiftObj> mySwiftObj_;
  • using: mySwiftObj_->someSwiftMethod();

So the question is, do these objects not collect garbage due to the circular link (I tried and deleted the circular link and they got GCed).

. ++: weak_ptr<SwiftObj> mySwiftObj_;... mySwiftObj_ GCed , swift. , , ++ - .

, ? ( null). , ?

!

+4
1

, /, , Djinni . ++ Swift , GC. Djinni -, , - , .

, Swift , Owner Listener. Listener Djinni someSwiftMethod(). , Djinni. . ASCII: Swift , ++ - .

                  <- Swift|C++ ->

  SwiftOwner ------------------------> CppObj
    ^    |                               |
    |    |                               |
 (weak)  |                               |
    |    v                               |
  SwiftListener <------------------------+

Swift, , , SwiftListener SwiftOwner . , Swift. SwiftOwner. ++, , ++, SwiftOwner. , SwiftOwner () , , .

+5

Source: https://habr.com/ru/post/1687393/


All Articles