Jump to content
  • Advertisement
Sign in to follow this  

[java] Cleaning up native memory

This topic is 4537 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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!