Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] incorrect use counter in Repository?

Thanks for the clarification.
That was important to understand.

-----Original Message-----
From: Shawn O. Pearce [mailto:spearce@xxxxxxxxxxx] 
Sent: Mittwoch, 15. September 2010 16:49
To: Kempin, Edwin
Cc: jgit-dev@xxxxxxxxxxx
Subject: Re: [jgit-dev] incorrect use counter in Repository?

"Kempin, Edwin" <edwin.kempin@xxxxxxx> wrote:
> I have a question regarding the implementation of org.eclipse.jgit.lib.Repository.
> However I'm a bit surprised by the initial value of the use counter, which is 1.

This is correct.  Its to support the notion of:

  Repository db = new FileRepositoryBuilder().setGitDir(...).build();
  ... do stuff ...

That is, when the Repository is constructed it is implicitly opened
once for the caller.  Calling close will release everything.

This isn't true when using the RepositoryCache.  Thee cache uses
the first open count for itself, to keep the Repository alive inside
of the cache.

> This means when I open a repository, work with it and the close the repository
> the use counter is back to 1 and the close method does not release any resources.
> I would expect that all resources are freed when close was as often called as the
> use counter was incremented.

Well, you don't normally call incrementOpen() yourself.  :-)
> I'm currently trying to implement rename of repositories in Gerrit and I noticed that
> some open file handles stay after working with a repository and closing it. The open
> file handles then prevent renaming the repository folder in the filesystem.

That is because the RepositoryCache still has this Repository open.
You need to use RepositoryCache.close() to make the cache drop the
reference and decrement the reference count.


Back to the top