Hi All,
I am trying to use RepositoryCache in JGit
3.4.1 to cache my repository objects. However this class seems to have a resource leak as explained below:
1. At the very start RepositoryCache does not cache any repositories.
2.
Call RepositoryCache.open(key) to open a repository on my file system.
It instanticates a FileRepository instance and the "useCnt" field of the
instance is initialized to "1". The "openRepository" method of class
"RepositoryCache" continues to call "db.incrementOpen()" after creating
the instance, and "useCnt" of repository instance will now be "2".
3. Call "repository.close()" against the returned repository instance after using it. The "repository.close()"
method decreases "useCnt" to "1", and return without calling "repository.doClose()" as "useCnt" has not reached "0".
4.
Now no strong references are pointing to the repository object created
above. RepositoryCache only holds a soft reference to this repository
and it will be released upon memory shortage to cause the repository
object being garbage collected.
During
above procedure, the "useCnt" field of repository object never reaches
"0" and "doClose" method of the repository is never called to release
object database and reference database. Is this a bug or there is
some other thing I am not aware of?
Thanks for taking time to look at this.
Regards
Robin