I'm instantiating from Swift non-ARC Objective-C classes transpiled from Java (J2ObjC), is it leak-safe?

297 Views Asked by At

I'm using J2ObjC for a project. I did setup everything and included my Java classes.

Only note is that I had to disable ARC because otherwise my Java codebase would not transpile/compile. (J2ObjC itself is recommended with arc disabled)

Since I wasn't able to disable for generated files only, I disabled it from Objective-C in Project Inspector -> Target -> Build Settings -> Apple LLVM 8.0 - Language - Objective C -> Objective-C Automatic Reference Counting (No)

Then I created my ViewController in Swift, and instantiated with no problems classes transpiled from Java (headers of generated .h files included in bridging header), and I have not to do any dealloc/release I should have to do in a Obj-C VC with no ARC.

Is this normal/leak-safe? By leak-safe that I mean that if I instantiate a transpiled class object, after the reference count decreases, it gets deallocated automatically as ARC-usual (I know ARC can't be disabled in Swift).

I know that I still have to watch out for reference cycles in Java classes but that's not what I meant by leak-safe.

1

There are 1 best solutions below

0
On

Why did you have to disable ARC? j2objc-generated code should work either with or without ARC (details here). We recommend not using ARC because it performs slightly slower for generated code, but with either memory model the code should correctly manage its memory.

As for leak-free, that can depend on the Java code, which can have reference cycles that aren't an issue with garbage collection. J2ObjC's cycle_finder can find many of these cycles, and running Xcode Instruments Leaks tool can find any others.