title: Do I Have to JNI Detach an Attached Thread?
body: <p>I have some native thread that needs to call into Java.  For that, I need to attach the thread to the VM using <code>AttachCurrentThread</code>.  Since this callback will happen quite often, the thread should probably stay attached.  Calling <code>AttachCurrentThread</code> multiple times is fine ("Trying to attach a thread that is already attached is a no-op.")</p>
  
  <p>Do I have to call <code>DetachCurrentThread</code> before the thread exits, will it happen automatically, or is it not even required?  What happens if I must call detach, but don't?  Would it just "leak," or could this even corrupt the VM state?</p>
  
  <p>I have checked the Java Native Interface specification, but either missed this, or it really is unspecified.</p>
  
  <p>My question applies specifically to Sun JDK 6 on Windows XP.</p>