Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Cleaning up native memory

Started by Whackjack Jun 14, 2006 at 7:42 PM 1 replies 950+ views
Original Post
Whackjack
Whackjack
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!
Whackjack
Whackjack
Excellent. This will make synchronization much easier. I'll just need to work out the details. Thank you!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.