The free Method Does Not Release A Temporary Lob After Calling getArray  (Doc ID 2122149.1)

Last updated on APRIL 06, 2016

Applies to:

JDBC - Version 11.2.0.1.0 and later
Information in this document applies to any platform.

Symptoms

We have an IN OUT LOB parameter of a stored procedure and use setARRAY for setting a temporary LOBs for this parameter. After calling getArray to retrieve the data, we wish to free the LOBs by using the free method. But if we confirm the Java heapdump, the memory occupied by the temporary LOBs appear not being reclaimed.

Here is a test showing this issue:

1. Create an array of LOBs and use it as IN OUT parameter of a stored procedure, as follows:

CREATE OR REPLACE TYPE ARRAY_BLOB AS TABLE OF BLOB;

CREATE OR REPLACE PROCEDURE testBlobArray(objs in out nocopy ARRAY_BLOB) IS
BEGIN
  DBMS_OUTPUT.PUT_LINE('hello');
END;

2. Create a java program to execute the stored procedure via JDBC, as follows:

//prepare statement
stmt =
(OracleCallableStatement) conn.prepareCall(
"{call testBlobArray(?)}");

//create the temporary LOB
BLOB blob = BLOB.createTemporary(connection, true, BLOB.DURATION_SESSION);
OutputStream outstm = blob.getBinaryOutputStream();
blob.open(BLOB.MODE_READWRITE);
outstm.write(bytes);
outstm.flush();

//construct the ARRAY object
ArrayDescriptor des = ArrayDescriptor.createDescriptor("ARRAY_BLOB",connection);
ARRAY arr = new ARRAY(des,connection,{blob});

//use setARRAY to pass the array to the stored procedure
stmt.setARRAY(1, arr);

//register the OUT parameter and execute
stmt.registerOutParameter(1, OracleTypes.ARRAY, "ARRAY_BLOB");
stmt.execute();

//call getArray to retrieve the data
Object[] arrayObje = (Object[]) stmt.getARRAY(1).getArray();

//free the temporary LOB
blob.free();

3. Run the java program and get java heapdump to confirm the memory

Cause

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms