Skip to content

Instantly share code, notes, and snippets.

@jfirebaugh
Forked from munkyboy/memleak.rb
Created May 16, 2011 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfirebaugh/974975 to your computer and use it in GitHub Desktop.
Save jfirebaugh/974975 to your computer and use it in GitHub Desktop.
script that shows memleak in jruby on certain windows platforms
require 'java'
require 'benchmark'
def foo
Benchmark.measure {
sc = org.jruby.embed.ScriptingContainer.new(org.jruby.embed.LocalContextScope::SINGLETHREAD, org.jruby.embed.LocalVariableBehavior::TRANSIENT)
sc.runScriptlet("require 'win32api'")
sc.runScriptlet("SHGetFolderPath = Win32API.new 'shell32', 'SHGetFolderPath', 'LLLLP', 'L'")
sc.terminate
sc = nil
}
end
i = 0
puts RUBY_DESCRIPTION
while(true)
i += 1
t = foo
JRuby.gc
printf "loop: %3d time: %*.4f mem: %10d\n", i, 7, t.total, Java::JavaLang::Runtime.getRuntime.totalMemory
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment