Sign in to follow this  

[java] Cleaning up native memory

This topic is 4198 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I thought about posting this in the DirectX forum, but it's more related to Java. Some of you might remember me working on a Java->DirectX wrapper. It's sort of sat on the back burner, but I've been designing in my head. Now I'm getting ready to move on to the next phase: binding the Java objects to their corresponding DirectX COM object. Now, the more experienced Java developers know that there's no guarantee that object finalizers will ever be called, even when the JVM exits. Therein lies the problem. If I have a Java object holding onto a handle to a COM object in native and the JVM subsequently exits, I can't guarantee that the COM object will be released. Now, the solution that I have so far is to have the Java objects attempt to release the COM reference (during normal application execution in the finalize() method). These objects will, instead of holding onto a pointer directly, have a key to a map. This will be used to get the COM object when it's needed. Then, when the process is being shutdown, the dll will watch for the exit code and release all of the COM objects manually. The only thing I'll need to work out is proper synchronization between the dll shutdown and a possible attempt by a finalize() call. I would prefer a nicer solution, so if anyone has any ideas ( Cas ;) ), let me know. Thanks!

Share this post


Link to post
Share on other sites

This topic is 4198 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this