Skip to content

loop allocates needless memory #2785

Closed
Closed
@ecin

Description

@ecin

Version: jruby 1.7.19 (1.9.3p551) 2015-01-29 20786bd on Java HotSpot(TM) 64-Bit Server VM 1.7.0_72-b14 +jit [darwin-x86_64]

Also reproducible on Java 8 (1.8.0 b25-b17).

Using loop seems to allocate needless memory when compared to while true:

require "java"
require "jruby"

thread = Thread.new { loop { } }
native_thread = JRuby.reference(thread).native_thread

thread_bean = java.lang.management.ManagementFactory.thread_mx_bean
loop { puts thread_bean.get_thread_allocated_bytes([native_thread.id].to_java(:long))[0]; sleep 1 }
# outputs ever increasing number

Thread.new { while true; end } does not cause the same unexpected memory allocation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions