[ http://issues.apache.org/jira/browse/DERBY-210?page=all ]

Deepa Remesh updated DERBY-210:
-------------------------------

    Attachment: derby-210-patch4-v2.diff
                derby-210-patch4-v2.status

Attaching a patch 'derby-210-patch4-v2.diff' which fixes the finalization code 
in Statement classes in client driver. This patch is in preparation for the 
fixes to memory leaks. 

Summary of changes: 

* Changes the finalizers in Statement classes to do only client-side cleanup. 
No network operations are done in the finalizers.

* Adds markClosed method to PreparedStatement class which overrides the 
markClosed method in Statement class. All client-side cleanup code is moved to 
markClosed method. Two forms of markClosed method are added:

    - markClosed() method will perform clean up but will not remove Statement 
from the open statements list and PreparedStatement from the commit and 
rollback listeners list in org.apache.derby.client.am.Connection. This method 
is called from finalize(), Connection#markStatementsClosed(), and to close 
positioned update statements. For the finaizer to be called, the Statement 
should not have any references and so it should have been already removed from 
the lists.  Connection#markStatementsClosed method explicitly removes the 
Statement from open statements list. Positioned update statements are not added 
to the open statements list. Hence, markClosed() is called in these cases.

    - markClosed(true) will additionally remove the statement objects from the 
lists. This is called from close() method.

* After these changes, it is not required to override close(), closeX() and 
finalize() methods in PreparedStatement class since they contain same code as 
in Statement class. So these methods are removed.

With these changes, I ran derbynetclientmats with Sun JDK 1.4.2. 
jdbcapi/dbMetaDataJdbc30.java failed. This test has been already fixed by 
David. 

Please take a look at this patch. Thanks.

> Network Server will leak prepared statements if not explicitly closed by the 
> user until the connection is closed
> ----------------------------------------------------------------------------------------------------------------
>
>          Key: DERBY-210
>          URL: http://issues.apache.org/jira/browse/DERBY-210
>      Project: Derby
>         Type: Bug
>   Components: Network Client
>     Reporter: Kathey Marsden
>     Assignee: Deepa Remesh
>  Attachments: DOTS_ATCJ2_Derby-noPatch.png, DOTS_ATCJ2_Derby-withPatch.png, 
> derby-210-patch1.diff, derby-210-patch2.diff, derby-210-patch2.status, 
> derby-210-patch3.diff, derby-210-patch4-v2.diff, derby-210-patch4-v2.status, 
> derby-210-v2-draft.diff, derby-210-v2-draft.status, derbyStress.java
>
> Network server will not garbage collect prepared statements that are not 
> explicitly closed by the user.  So  a loop like this will leak.
> ...
> PreparedStatement ps;
>  for (int i = 0 ; i  < numPs; i++)
>       {
>        ps = conn.prepareStatement(selTabSql);
>        rs =ps.executeQuery();
>        while (rs.next())
>       {
>           rs.getString(1);
>       }
>       rs.close();
>       // I'm a sloppy java programmer
>       //ps.close();
>       }
>                       
> To reproduce run the attached program 
> java derbyStress
> Both client and server will grow until the connection is closed.
>  
> It is likely that the fix for this will have to be in the client.  The client 
> does not send protocol to close the prepared statement, but rather reuses the 
> PKGNAMCSN on the PRPSQLSTT request once the prepared statement has been 
> closed. This is how the server knows to close the old statement and create a 
> new one.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Reply via email to