I wrote a simple Sinatra app that takes any String from a URL parameter,
stores that value as an attribute of a Java DTO (MessageHolder.java),
and renders an ERB template that displays that value back in an HTML
page. The complete source can be found here:
The strange behavior I noticed when profiling the app is the first
will create a MessageHolder object on the heap (as expected) and when I
force garbage collection, the object is reclaimed (again as expected).
However, any subsequent call:
will create a MessageHolder object on the heap, and forcing garbage
collection does NOT reclaim the object. I took a look at a heap
snapshot, and can’t figure out why the org.jruby.RubyThread is
keeping a reference to my Java DTO.
I’m running my app with Tomcat 6 (although I experience the same
problem with 7), Java 1.6, JRuby 1.7.0, and a war built using Warbler.
Attached is a screenshot of the heap snapshot. I’m sure there’s
something obvious I’m missing here, but I cannot figure out what I’m
doing wrong. Any help or insight would be greatly appreciated!