git2-rs
git2-rs copied to clipboard
clone a Repo, The memory has increased from 1m to 20m and will not be released
I use this code to clone repo, The memory has increased from 1m to >20m and more。And will not be released
fn clone(){
let mut callbacks = RemoteCallbacks::new();
callbacks.credentials(|_url, username_from_url, _allowed_types| {
Cred::userpass_plaintext("abc","abcd)
});
// Prepare fetch options.
let mut fo = git2::FetchOptions::new();
fo.remote_callbacks(callbacks);
// Prepare builder.
let mut builder = git2::build::RepoBuilder::new();
builder.fetch_options(fo);
let r= builder.clone(
"http://xxxx.git",
Path::new("/code-analyse/"),
);
match r{
Ok(repo) => {println!("ok") }
Err(e) => {println!("{}",e)}
}
}
Can you say how you are measuring the memory usage? Allocators sometimes don't release unused memory back to the operating system, so perhaps it was just a spike?
I just observe the memory situation of the process(code-analyse-server), from the initial <1m, after cloning the repo, it rises to >20m, then it will drop to about 10m, and then keep
just started:

clone some repo:

down to a certain level and keep

I'm not sure what those screenshots are from, but if that is from a process viewer, I think that would be expected to some degree. As I mentioned, allocators won't always release pages back to the operating system. The memory may be fragmented, or it may be caching pages for quick reuse. It is generally not a concern since the OS can remove unused pages from RAM when needed.
I tried your example with some instrumentation. libgit2_sys::init() allocated about 100k of global stuff because libgit2 has some global structures. Otherwise, I did not see any leaks during the clone operation, and memory was released after the clone call finished.