title: Do I need to explicitly dispose a jbyteArray?
body: <p>I am writing a function which first creates a new <code>jbyteArray</code>, which, if everything else works, it will return.  If everything else is not successful in the function it will return NULL instead.</p>
  
  <p>However if an error occurs somewhere during the function <em>after</em> I have successfully called <code>NewByteArray()</code>, so I need to <em>explicitly</em> dispose of the jbyteArray before returning, or can I simply leave it to the garbage collector ?</p>
  
  <p>In a rough code sketch :</p>
  
  <pre><code>jbyteArray makeAndFill( JNIEnv *env )
  {
    jbyteArray ba = NULL ;
  
    ba = (*env)-&gt;NewByteArray( env, 1000 ) ;
  
    if( ba == NULL )
      return NULL ;
  
    /* so far so good /
  
    if( fillme( ba ) )
    {
     /* Whoops, a problem ...
      *
      * DO I need to free the jbyteArray explicitly before
      * returning NULL ?
      */
  
     return NULL ;
    }
  
    /* everything was fine
     */
  
    return ba ;
  }
  </code></pre>
  
  <p>You can assume that fillme() does all the required Get and Release code and simply returns FALSE if soem some reason it had a problem.  If fillme() cannot do it's job properly we simply want the function to return a NULL.</p>
  
  <p>My understanding is that if I do not return the jbyteArray to JAVA "proper" from JNI it will simply be garbage collected.  Is that correct ?</p>