Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Cecil Westerhof Newsgroups: comp.lang.java.programmer Subject: gc is freeing and claiming memory Date: Fri, 12 Aug 2016 15:56:23 +0200 Organization: Decebal Computing Lines: 34 Message-ID: <87oa4yks54.fsf@Equus.decebal.nl> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="12baf5125b19322b899c79c2e3878015"; logging-data="3481"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+7bN3e3sq5YzAaO3kqZ97s5XQIEBgwcCQ=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-Homepage: http://www.decebal.nl/ Cancel-Lock: sha1:aGuI73nCAvOGeI0ePbarSidgO68= sha1:02Ic2gcXCKi6XzZ039Zg6qYgw28= Xref: csiph.com comp.lang.java.programmer:35273 Because I saw certain applications took a lot of residential memory and swap space I am looking a bit into memory management. I have the following code: long freeMemory = rt.freeMemory() / divideValue; long totalMemory = rt.totalMemory() / divideValue; logMessage(String.format("Maximum to use %d", rt.maxMemory() / divideValue)); logMessage(String.format("Before %d - %d = %d", totalMemory, freeMemory, totalMemory - freeMemory)); System.gc(); freeMemory = rt.freeMemory() / divideValue; totalMemory = rt.totalMemory() / divideValue; logMessage(String.format("After %d - %d = %d", totalMemory, freeMemory, totalMemory - freeMemory)); One of the outputs is: 15:33:03: Maximum to use 228 15:33:03: Before 142 - 80 = 62 15:33:03: After 146 - 93 = 53 So while on the one hand there is 9 MB of memory freed, but at the same time there is another 4 MB reserved. (I have seen a bigger difference, there was on the one hand 4 MB freed and at the same time 32 MB extra reserved. But I did not save that.) What is happening here? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof