Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
I think I know the answer to this, but I want an informed opinion. I've looked through the JLS and API, and as best I can tell, objects created by a native call (meaning objects that might be created by a C++ program that was called from a Java app) are not garbage collected by the JVM. Is this a correct assertion?
Bingo, that is absolutely correct. That's the main reason why the finalize() method exists, so you can release memory not allocated by the JVM. Of course, since there's no real guarantee that your finalize() method will actually get called, it's not a very good place to release your native objects. It's much much safer to always do this kind of clean up in a finally clause. But however you clean up your native objects, you must ensure you do deal with it, otherwise you'll be leaking memory and the gc will be unable to save you.
Thanks for the response - I just wanted someone else to corroborate it (sorry - bad pun ). I had someone pose this question to me and I was pretty sure I knew the answer. I went over to the JNI Specification and looked this up also. Seems there are some pretty ugly ways you can leak memory.
SCJP, SCJD, SCWCD, SCEA Part I
Hey, I'm supposed to be the guide! Wait up! No fair! You have the tiny ad!
Free, earth friendly heat - from the CodeRanch trailboss