im reading and parsing a bunch of .txt files, nothing crazy. no unsafe involved. my program has already exited, but RAM usage is still through the roof, without taskmanager or resource monitor showing which process is holding it (see images). any ideas whats going on here?
#is this a memory leak?
74 messages · Page 1 of 1 (latest)
even if you had a memory leak the memory should be freed on program exit
yeah thats what confuses me
i know i can just reboot and that will most likely fix it, but i'd like to actually figure out whats going on
Any chance it's just the file cache, meaning it will get evicted as soon as any process needs memory?
lol sweatremoval
Pretty sure it's just cache
but how can 1.5gb of files cause 30gb of ram usage?
like even if it held literally everything in ram that wouldnt even come close
im suspecting rust-analyzer
well, try the allocation first
will a simple vec![0u8; 10_000_000_000] suffice?
sure yeah
right, well you can try using them
add a sleep() after it and black_box it
i tried mutating it with indices i input with stdin
fn main() {
let mut x = vec![0_u8; 10_000_000_000];
loop {
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
let i = s.trim_end().parse::<usize>().unwrap();
x[i] = 42;
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
let i = s.trim_end().parse::<usize>().unwrap();
println!("{}", x[i]);
}
}
dunno what that is, but im on a fresh windows 11 install
fresh as in 1 day old
closed everything:
still over 26gb occupied
and the code i posted earlier supposedly uses 300kb only
ooh its using virtual memory
Oh, yeah, you'll have to actually use each memory page in order to have them in RAM
A loop would help
fn main() {
let mut x = vec![0_u8; 10_000_000_000];
for i in 0..x.len() {
x[i] = (i % 256) as _;
}
loop {
let i = read_input();
x[i] = read_input() as _;
let i = read_input();
println!("{}", x[i]);
}
}
fn read_input() -> usize {
let mut buf_string = String::new();
std::io::stdin()
.read_line(&mut buf_string)
.unwrap();
buf_string
.trim_end()
.parse()
.unwrap()
}
now it shows up properly
but it seems to struggle to acquire the memory
i'd expect to be able to start inputting stuff after a few seconds at most
but after a minute it still didnt let me
so i assume its constantly swapping pages?
I mean, it's not surprising your computer would struggle to free up 10 GB of RAM on your whim
really? i thought the whole point of RAM is exactly that
If a process has recently written to RAM, the OS has to write that page to disk before assigning it to you. If you do that for 10 000 000 pages, that takes a while.
im not an expert, but i feel like this would kinda defeat the point of having ram in the first place
could you try the code yourself and tell me how it performs on your machine?
Yours isn't the only process that uses RAM.
so what
But anyways, it does appear not all of the 10 GB you decided to take up for yourself was file cache or already commited pages.
What you could try is to keep allocating RAM until it takes more than one second to perform a write, and then immediately quit.
i've let it run for a while now, and my entire system started lagging
until i eventually got this
and shouldnt exiting the process free up all the memory?
It should free up the process's private memory. It may not free up the files that the process read.
but again, its just 1.5gb of files, nowhere near enough to explain the 20+ im looking at
my target is 3.2gb
idk i find it hard to believe that this is normal
RAMMap64 from sysinternals
interesting that it says 11gb is unused
i dont really know what any of this means, just throwing stuff out here
Well it seems your memory cleaner did clean your memory...
except that task manager still reports 99% usage

Do you happen to have wsl?
its installed (for docker desktop), but i havent used it yet
You can disregard me then
as expected, the problem was gone after the reboot, so i dont think we'll ever figure out what it was
wsl just has the possibility to eat memory that windows can't see