@Callback private static void release(@Pointer long self, @Pointer long sel) { int count = ObjCRuntime.int_objc_msgSend(self, retainCount); if (count <= 2) { synchronized (CUSTOM_OBJECTS) { CUSTOM_OBJECTS.remove(self); } } long cls = ObjCRuntime.object_getClass(self); if (logRetainRelease) { logRetainRelease(cls, self, count, false); } Super sup = new Super(self, getNativeSuper(cls)); ObjCRuntime.void_objc_msgSendSuper(sup.getHandle(), sel); }
@Callback static void release(@Pointer long self, @Pointer long sel) { int count = ObjCRuntime.int_objc_msgSend(self, retainCount.getHandle()); if (count == 1) { long owner = VM.getPointer(self + OWNER_IVAR_OFFSET); synchronized (ASSOCIATED_OBJECTS) { ASSOCIATED_OBJECTS.remove(owner); } } if(logRetainRelease) { long cls = ObjCRuntime.object_getClass(self); logRetainRelease(cls, self, count, false); } ObjCRuntime.void_objc_msgSendSuper(new Super(self, NS_OBJECT_CLASS).getHandle(), sel); } }
@Callback private static void dealloc(@Pointer long self, @Pointer long sel) { // during dealloc UIView calls removeFromSuperView or other api which will cause // retain to be called due ARC or other logic, which will break java CUSTOM_OBJECTS // mechanism. So let it to deallow with extra retains long cls = ObjCRuntime.object_getClass(self); Super sup = new Super(self, getNativeSuper(cls)); ObjCRuntime.void_objc_msgSendSuper(sup.getHandle(), sel); // and after this remove this peer (as it could be added again due unexpected retain calls) synchronized (CUSTOM_OBJECTS) { CUSTOM_OBJECTS.remove(self); } }
@Callback static void release(@Pointer long self, @Pointer long sel) { int count = ObjCRuntime.int_objc_msgSend(self, retainCount.getHandle()); if (count == 1) { long owner = VM.getPointer(self + OWNER_IVAR_OFFSET); synchronized (ASSOCIATED_OBJECTS) { ASSOCIATED_OBJECTS.remove(owner); } } if(logRetainRelease) { long cls = ObjCRuntime.object_getClass(self); logRetainRelease(cls, self, count, false); } ObjCRuntime.void_objc_msgSendSuper(new Super(self, NS_OBJECT_CLASS).getHandle(), sel); } }
@Callback private static void release(@Pointer long self, @Pointer long sel) { // this callback is required to remove reference to java counterpart once // native part is being released. dealloc can't be used for purpose // as there is direct retain in afterMarshaled for custom objects int count = ObjCRuntime.int_objc_msgSend(self, retainCount); if (count <= 2) { synchronized (CUSTOM_OBJECTS) { // at this moment there is no reference kept for java object // and it is subject for GC if not being referenced anywhere // once GC comes it will cause release() to be called in dispose // which will also release native part CUSTOM_OBJECTS.remove(self); } } long cls = ObjCRuntime.object_getClass(self); if (logRetainRelease) { logRetainRelease(cls, self, count, false); } Super sup = new Super(self, getNativeSuper(cls)); ObjCRuntime.void_objc_msgSendSuper(sup.getHandle(), sel); }