3 ms·
Fully agree. This is a well known issue that users of native interop from managed languages commonly encounter when they first start out. One of the first bugs
by barrkel 12y ago
Fully agree. This is a well known issue that users of native interop from managed languages commonly encounter when they first start out. One of the first bugs I found in .NET related to this; the Ping component didn't expect that Finalize could be called on the same instance before a method on that instance finished executing.
What is less convenient is that Java doesn't have a handy method to ensure that an object is reachable, that the JVM won't optimize away or eliminate. .NET has GC.KeepAlive; AFAIK, Java doesn't have an equivalent. I asked a question about this on SO[1] some time ago. An approximate equivalent can be cobbled together, with probabilistic assignments to a volatile variable.
[1] http://stackoverflow.com/questions/22457002/whats-the-java-equivalent-of-nets-gc-keepalive http://stackoverflow.com/questions/22457002/whats-the-java-e...