对于我正在编写的这种方法,我正在使用 jgit 库克隆一个 git repo,然后对这些文件做一些事情,最后我想删除 repo。我遇到的问题是,当我在 .pack 文件(位于 .git\objects\pack 中)上调用 delete() 方法时,它无法被删除。但是可以删除所有其他文件。为什么会这样?
问问题
6418 次
2 回答
11
刚刚找到了一种干净的方法:在使用你的 repo 完成操作之后,以这种方式关闭你的 git 对象:
Git git;
...
git.getRepository().close();
//then delete files
于 2015-05-12T07:23:44.047 回答
4
您可以看到基于 JGit 的 Java 应用程序在默认情况下倾向于禁用 ddd。例如,请参阅Gitblit
的
此配置文件:
# When true, JGit will use mmap() rather than malloc()+read() to load data from
# pack files. The use of mmap can be problematic on some JVMs as the garbage
# collector must deduce that a memory mapped segment is no longer in use before
# a call to munmap() can be made by the JVM native code.
#
# In server applications (such as Gitblit) that need to access many pack files,
# setting this to true risks artificially running out of virtual address space,
# as the garbage collector cannot reclaim unused mapped spaces fast enough.
#
# Default on JGit is false. Although potentially slower, it yields much more
# predictable behavior.
# Documentation courtesy of the Gerrit project.
#
# SINCE 1.0.0
# RESTART REQUIRED
git.packedGitMmap = false
这与您找到的JGit 线程一致:
我遇到了另一个无法在 Windows 中删除克隆存储库的实例。
这似乎与“PackedGitMMAP
”的使用有关。
这是尝试使用虚拟内存映射的已知问题吗?是的。
问题是 JVM 不会释放内存映射,直到映射被 Java GC 垃圾收集。
这可能在未来的任何时候发生,如果没有足够的内存压力迫使 GC 真正寻找垃圾并回收,则可能永远不会发生。
这就是我们默认禁用该功能的原因,我们无法预测 JVM 何时最终会释放文件。在这个测试用例中,如果我 "
setPackedGitMMAP=false
" 则存储库被成功删除。是的。这就是为什么这是默认设置。
于 2013-10-06T08:41:50.180 回答