Hi Shawn,
I have updated the doco to show how to use the try-with-resource.
Thanks !
On 14/07/2022 04:09, Maxim Solodovnik wrote:
try (SearchCursor searchResults = search( …);) {
.....
}
:)))
On Thu, 14 Jul 2022 at 02:11, Shawn McKinney <smckin...@apache.org> wrote:
Hello,
Recently noticed the fortress code is not closing the search cursor. Take the
GroupDAO.find[1] example (listed below).
Same pattern across the codebase despite clear warnings in the doc:
"Don’t forget to close the cursor, otherwise the associated data remains in
memory forever (causing a memory leak)! Best practice is to use try-with-resources
statement.” [2]
Obviously, we don’t want to be leaking. What’s the recommendation here, should
I change the code?
GroupDAO.find
```java
List<Group> find( Group group ) throws FinderException
{
...
SearchCursor searchResults;
try
{
...
searchResults = search( …);
while ( searchResults.next() )
{
groupList.add( unloadLdapEntry( searchResults.getEntry(), sequence++ ) );
}
…
catch ( CursorException e )
{
// no cursor close here
}
catch ( LdapException e )
{
// or here
}
finally
{
closeAdminConnection( ld );
// and worse? Not here either
}
return groupList;
}
```
—
Shawn
[1](https://github.com/apache/directory-fortress-core/blob/master/src/main/java/org/apache/directory/fortress/core/impl/GroupDAO.java)
[2](https://directory.apache.org/api/user-guide/2.3-searching.html)
---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscr...@directory.apache.org
For additional commands, e-mail: api-h...@directory.apache.org
--
*Emmanuel Lécharny - CTO* 205 Promenade des Anglais – 06200 NICE
T. +33 (0)4 89 97 36 50
P. +33 (0)6 08 33 32 61
emmanuel.lecha...@busit.com https://www.busit.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscr...@directory.apache.org
For additional commands, e-mail: api-h...@directory.apache.org