heap space not released by the end of program ?

124 views
Skip to first unread message

Chan Lewis

unread,
Jul 12, 2021, 10:52:24 PM7/12/21
to golang-nuts
Hi, I wrote a test program, which tests when GC starts to return heap space to OS.

But I've waited for a long time and haven't seen the RSS memory reduced. I can't figured out why, Any help ? (go version 1.14.3)

Kurtis Rader

unread,
Jul 13, 2021, 12:20:41 AM7/13/21
to Chan Lewis, golang-nuts
I didn't look at the source for your program because you  don't seem to understand what "resident set size" means in this context. The RSS of a process is unrelated to its virtual size. You appear to be equating RSS and virtual size. This might be an example of the XY Problem.. What Prompted you to open this discussion thread?

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/a511d995-7f1d-431d-9065-6b6d287a19dan%40googlegroups.com.


--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

Robert Engels

unread,
Jul 13, 2021, 12:45:17 AM7/13/21
to Kurtis Rader, Chan Lewis, golang-nuts
RSS is the amount of memory mapped to physical memory. It doesn’t include memory swapped. Still, if GC was releasing pages back to the OS - unmapping the allocated and touched pages - the RSS should decrease. 

There was a previous thread on if and when GC will release pages back to the OS. This is hard to do if you do not have a compacting collector - Go does not - so it is doubtful Go ever releases the pages once allocated to the heap. 

On Jul 12, 2021, at 11:20 PM, Kurtis Rader <kra...@skepticism.us> wrote:



Brian Candler

unread,
Jul 13, 2021, 5:34:25 AM7/13/21
to golang-nuts
There was a change in go 1.16 which could affect this, so I suggest you try the latest go.

Previously, go just marked the pages as "can be freed when required" - but the OS would not actually free them until under memory pressure. Now it tells the OS to free them immediately.

Robert Engels

unread,
Jul 13, 2021, 8:31:37 AM7/13/21
to Brian Candler, golang-nuts
I knew I had seen something on that. :)

I guess Go doesn’t need a compacting collector if it can allocate most objects on the stack to avoid fragmentation. 

On Jul 13, 2021, at 4:34 AM, Brian Candler <b.ca...@pobox.com> wrote:


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages