I have two djinni interfaces, one to be implemented in Swift/objective C/java SwiftObj and one to be implemented in C++ CPPObj.
SwiftObj = interface +o +j {
someSwiftMethod();
}
CPPObj = interface +c {
static create(swiftObj: SwiftObj): CPPObj;
someCPPMethod();
}
They both have a pointer to each other, so the SwiftObj will be able to call someCPPMethod() of the CPPObj and viceversa: CPPObj will be able to call someSwiftMethod() from the SwiftObj:
In swift:
- the class variable:
var myCPPObj: SwiftObj! - the creation:
myCPPObj = MyCPPObj.create(self) - the usage:
myCPPObj.someCPPMethod()
In c++:
- the class variable:
shared_ptr<SwiftObj> mySwiftObj_; - the usage:
mySwiftObj_->someSwiftMethod();
So the question here is, these objects are not getting garbage collected due to the circular reference (I tried and removed the circular reference and they got GCed).
But then I tried setting one of those pointers as weak. In C++: weak_ptr<SwiftObj> mySwiftObj_; ... but this made the mySwiftObj_ be GCed instantly, even while it actually still exists in swift. Same thing happened when I set the swift pointer as weak and the C++ as strong.
So how can I deal with this situation? (other than manually setting one of those pointers as null). Any insights on how the pointers actually work in djinni?
Thanks!