Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak #2791

Closed
mrkaspa opened this issue Apr 1, 2015 · 3 comments
Closed

Memory leak #2791

mrkaspa opened this issue Apr 1, 2015 · 3 comments

Comments

@mrkaspa
Copy link

mrkaspa commented Apr 1, 2015

This algorithm runs perfect with ruby 2.2.0 but with jruby 1.7.16 I got memory leaks until I put the memory to 4GBs

require "benchmark"

num_rows = 100000
num_cols = 10
data = Array.new(num_rows) { Array.new(num_cols) { "x"*1000 } }

time = Benchmark.realtime do
  csv = data.map { |row| row.join(",") }.join("\n")
end

puts time.round(2)
@cheald
Copy link
Contributor

cheald commented Apr 2, 2015

Your setup creates 100,000 objects, each of which is 1000 bytes + overhead. Then, your benchmark creates a new 10,009 byte string for each row, and then collects them all into an array of 100k 10kb entries (1GB + substantial overhead), then attempts to join them together into one giant string which will require an additional whopping 1,000,999,999 bytes, without considering overhead.

This isn't a leak - this is just requesting more memory than you've allocated to the JVM. Running this under MRI requires about 3GB of RAM. MRI doesn't have explicit limits like the JVM does, and will happily continue allocating memory until your machine grinds into a swapping heap of rubble. If you want to perform operations that require large amounts of allocated RAM, you'll need to provide sufficient memory to the JVM.

@mrkaspa
Copy link
Author

mrkaspa commented Apr 2, 2015

Ok thanks

@nirvdrum
Copy link
Contributor

nirvdrum commented Apr 2, 2015

Closing due to @cheald's comprehensive analysis.

@nirvdrum nirvdrum closed this as completed Apr 2, 2015
@enebo enebo added this to the Invalid or Duplicate milestone Apr 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants