From the py4j official blog (yes it's an ancient blog), the following quoted sentence doesn't seem to be reasonable to me.
if javaObject is no longer referenced in the Python program, javaObject could be garbage collected before method1() is called.
The author further explains that for a javaObjet.method1()
statement, the order of operations could be
- get attribute method1()
- decrease reference count of javaObject
- garbage collect javaObject on Python VM
- garbage collect javaObject on Java VM
- call method1.__call__() method
- call javaObject.method1 on Java VM
- Error!!! javaObject no longer exists on the Java VM!
How does javaObject
get garbage collected when it is calling the method1
?