I know this question is a frequently one, however I checked some solutions from this site, but it seems like it didn’t work for me.
So, I have written a small java program, and I want to know how much memory it consumes at different execution moments. I tried Runtime.getRuntime.total() and Runtime.getRuntime.free(), but I’m getting the (almost) same results each time.
I am not interested in how much memory is there available or used by the entire JVM, I want to know specifically for my java process.
this will get you how much heap memory your process has used.
you can also get all your memory pools and iterate through them to determine other memory usage
you could also use jvisualvm to interrogate your application.