[ruby-core:114674] [Ruby master Misc#19870] Why is a long-run thread allocated more memory than a short-run one?

Issue #19870 has been reported by caracal (Taishi Kasuga). ---------------------------------------- Misc #19870: Why is a long-run thread allocated more memory than a short-run one? https://bugs.ruby-lang.org/issues/19870 * Author: caracal (Taishi Kasuga) * Status: Open * Priority: Normal ---------------------------------------- I want to write multithreading programing in Ruby but I found the following memory consumptions. ``` $ irb irb(main):001> require 'objspace' => true irb(main):002> t1 = Thread.new {} => #<Thread:0x00007f9237a74b28 (irb):2 run> irb(main):003> t2 = Thread.new { sleep 6000 } => #<Thread:0x00007f9237b4f1d8 (irb):3 run> irb(main):004> t3 = Thread.new { loop { sleep 5 } } => #<Thread:0x00007f9237b6d840 (irb):4 run> irb(main):005> ObjectSpace.memsize_of(t1) => 360 irb(main):006> ObjectSpace.memsize_of(t2) => 1048936 irb(main):007> ObjectSpace.memsize_of(t3) => 1048936 irb(main):008> ``` Is the above behavior legitimate? -- https://bugs.ruby-lang.org/

Issue #19870 has been updated by nobu (Nobuyoshi Nakada). Status changed from Open to Feedback 1048936 - 360 = 1048576 = 0x100000 A terminated thread no longer keeps its stack area. ---------------------------------------- Misc #19870: Why is a long-run thread allocated more memory than a short-run one? https://bugs.ruby-lang.org/issues/19870#change-104505 * Author: caracal (Taishi Kasuga) * Status: Feedback * Priority: Normal ---------------------------------------- I want to write multithreading programing in Ruby but I found the following memory consumptions. ``` $ irb irb(main):001> require 'objspace' => true irb(main):002> t1 = Thread.new {} => #<Thread:0x00007f9237a74b28 (irb):2 run> irb(main):003> t2 = Thread.new { sleep 6000 } => #<Thread:0x00007f9237b4f1d8 (irb):3 run> irb(main):004> t3 = Thread.new { loop { sleep 5 } } => #<Thread:0x00007f9237b6d840 (irb):4 run> irb(main):005> ObjectSpace.memsize_of(t1) => 360 irb(main):006> ObjectSpace.memsize_of(t2) => 1048936 irb(main):007> ObjectSpace.memsize_of(t3) => 1048936 irb(main):008> ``` Is the above behavior legitimate? -- https://bugs.ruby-lang.org/
participants (2)
-
caracal (Taishi Kasuga)
-
nobu (Nobuyoshi Nakada)