Search code examples
javajdbcblobclob

Do java.sql.Array/Blob/Clob types need to be "free()"ed?


Do I need an explicit to call free() on Arrays, clobs etc... or will closing the ResultSet and/or Statement automatically take care of this? The javadoc doesn't say anything, so I assume that it's not necessary, but I would hate to make an incorrect assumption.

Also, if its not necessary, is it a good idea if you're going to close the result set right away? I could see how it might help if you're not going to do so.


Solution

  • It depends on the Vendor and JDBC version you are using. As all database vendors do not support Array(e.g. MySQL)

    And this could be the reason Why the javadoc doesn't say anything.

    I have found this tutorial Using Array Object on oracle site's JavaSE tutorials which says to release resources explicitly.

    Here is another link which illustrates scenario of on free(). JDBC 4's java.sql.Clob.free() method and backwards compatibility

    if its not necessary, is it a good idea if you're going to close the result set right away?

    I think then there should not be required to free(),but again if its a long running transacation,then its good to call free().

    Quoting from the tutorial:

    Array objects remain valid for at least the duration of the transaction in which they are created. This could potentially result in an application running out of resources during a long running transaction. Applications may release Array resources by invoking their free method.