In a parallel application, threads(32) in a thread group use a shared unmanaged and standalone disposable object.
We have the same thing in our c/c++ app, and there I use shared_ptr<>
in order to let object dispose and finalize just after there is no need to the object.
I just tried to apply the same thing in Java, and I faced with finalize()
method. But there are some problems, because of GC is so lazy sometimes, the object doesn't even identified as unreachable object for disposing/finalizing, sometimes it is called, but there is no warranty GC lets the object invoke the finalize()
completely.
So I just came with another complex solution which I just count down and track the threads are using the object which it doesn't work too, but I know this is not a reliable solution, and I know I will faced with unexpected results.
I'm just wonder if there is something equivalent to shared_ptr<>
in java, or is it possible to handle the object via JNI?
Any ideas?