JRuby Swing GUI run-away memory usage

This program works, but it has the following issues:

(Note: This post was deleted and re-submitted in order to update the
file list. There is now in the troublshooting folder, a listing of the
Object_tracking log, which was missing from the original posting.)

See the Screenshot photo in the topmost folder for how I use this app.
Also, the screenshot
shows the System Monitor, with two of these apps running, the one
highlighted has run for hours and uses 126.5 MiB of memory, where as the
instance that was just started uses 95.3 MiB of memory, but the memory
usage can increase by 10 MiB in just a minute or two.

The app is doing nothing by refreshing the window every minute. It is
not doing anything that should require more memory as it runs.

Also, several times the app has caused my computer to go to 100% on one
processor core for what has been as short as a couple of minutes, to
well over ten minutes (after which I “killed” the program, as it would
not respond or close). I don’t know if JRuby was doing a massive garbage
collection, or if the program had crashed. On at least one occasion, the
app was still operational after it went back to normal CPU usage, except
that the clock display incremented late, by twenty seconds, as though
the program had stopped for twenty seconds.

Problem 1:
The app starts with about 92 MiB, and quickly increases its memory usage
up to almost 150 MiB. What can I change in my program to keep the memory
usage from running away?
In the “Troubleshooting” folder, are some memory dumps.

Problem 2:
When I am using the Google Chromium web browser, and working on one
particular site, the behavior of my JRuby GUI becomes erratic, and even
crashes. I have only experienced this with one particular website:

I typically have four tabs with this same webpage open at once, where I
type in a word that I want the website dictionary to look up for me.
Eventually, the website stops responding, and my JRuby app has
malfunctioned, or crashed. Could it be that the Chromium web browser is
sharing memory with Java or JRuby, and somehow the shared memory is
getting corrupted?

My System Monitor shows that 1.5 GiB of 3.7 GiB of RAM is typically
being used at these times.

In the “Troubleshooting” folder, are some memory dumps.

Problem 3:
This is not a critical issue (the above issues are). However, when I use
JWindow for my GUI, it operates in an “always on top” fashion from a
display point of view, meaning that I can “type right through it” to the
underlying editor applicaton. JWindow is ignoring everything but
right-clicks, which is what I want, but it is remaining on top of the
other apps that have the focus. I found on the Internet a comment that
this was a bug unique to Gnome, but that was a several year old comment,
and it said that the bug had been fixed. I have not tried my app on
Windows, so I don’t know whether this is a Gnome issue or not.

Explanation relative to the window type:
In searching the Internet for how to produce a window that:

  1. has no border (undecorated)
  2. has no taskbar icon
  3. is not “always on top”

I was frustrated by the lack of answers of how to create such a window,
and especially the most common remark was: “Well why would anyone want
to do that?”
So I will explain why now. If you look at my screenshot, you will see
exactly that kind of window, except that it does have a taskbar icon. I
don’t want a task bar icon, because I will often have many of these
borderless windows running at the same time and I don’t want to fill up
my taskbar with icons for these windows. I don’t need a border or
taskbar icon for this type of window, since I control everything through
my right-click menu.

I can get two of three of these requirements (so far). The JWindow does
not produce the taskbar icon, but it seems to be stuck “always on top”.
The doc’s say that it does not have to be “always on top”, so I assume
that it has a bug now.

JDialog was suppose to not have a taskbar icon, but it does. JFrame and
JDialog work perfectly for my application, but they produce a taskbar
icon. If I could “turn off” the taskbar icon for either of these, then I
would have what I had when I used wxRuby.

Why no border? I use these windows as “keep me informed” images on my
desktop. I may group several of them together, or separately in various
parts of the screen. The border just wastes screen space. These windows
are not being worked with, they are just “background information” lying
there on my screen, waiting for me to notice them. Most of the time,
they are covered up by the windows that I am working with.

My computer:
Sony Vaio VPCZ1, Intel quad-core, 2.5GHz, 4GB Ram, SolidState Hard Drive
Screen: 1600 x 900, The top 25 pixels are the only system area, for
the panel.
Ubuntu 11.04 Desktop 64 bit, running Gnome (not Unity).
Java from Ubuntu repository: sun-java6-jdk (6.26-1natty1)
JRuby-1.6.3 installed by RVM. (RVM + Bundler configuration)
Rails is not installed.
NetBeans 7.0 IDE

Long post, but I have a few replies inline below…

On Wed, Aug 3, 2011 at 10:00 PM, Gary H. [email protected]
wrote:

See the Screenshot photo in the topmost folder for how I use this app.
Also, the screenshot
shows the System Monitor, with two of these apps running, the one
highlighted has run for hours and uses 126.5 MiB of memory, where as the
instance that was just started uses 95.3 MiB of memory, but the memory
usage can increase by 10 MiB in just a minute or two.

The JVM has a tendency to use whatever memory you want to give it. By
default, JRuby allows the JVM to grow up to a max heap size of 500MB,
where actual max process size will be that plus some amount of
non-heap data (like 50-100MB, depending on what you’re doing). Do you
actually get memory errors, or does the app just seem “greedy”?

You can force JRuby/JVM to limit heap memory to a smaller size by
passing -J-Xmx200M or similar.

The app is doing nothing by refreshing the window every minute. It is
not doing anything that should require more memory as it runs.

“Doing anything” can cause the JVM to decide it needs more “breathing
room”. Limiting heap size can reduce the JVM’s tendency to be
“greedy”.

Also, several times the app has caused my computer to go to 100% on one
processor core for what has been as short as a couple of minutes, to
well over ten minutes (after which I “killed” the program, as it would
not respond or close). I don’t know if JRuby was doing a massive garbage
collection, or if the program had crashed. On at least one occasion, the
app was still operational after it went back to normal CPU usage, except
that the clock display incremented late, by twenty seconds, as though
the program had stopped for twenty seconds.

If you’re not near the heap size limit, this would probably indicate a
bug of some kind, either in your code or in JRuby (or, more rarely, in
the JVM/JDK). Need more information here, like a heap dump (use
“jstack” command or Ctrl-\ in the terminal where you’re running the
app to get a thread dump, for example).

Problem 1:
The app starts with about 92 MiB, and quickly increases its memory usage
up to almost 150 MiB. What can I change in my program to keep the memory
usage from running away?
In the “Troubleshooting” folder, are some memory dumps.

We can take a look, but please describe whether the app just seems
“greedy” or if it actually grows to a point where it starts to fail
catastrophically.

getting corrupted?
It sounds more like at some point the amount of memory used by apps on
your system starts to go into swap space. This could explain many of
the effects you’re seeing. What’s the utilization of physical system
memory in these situations?

My System Monitor shows that 1.5 GiB of 3.7 GiB of RAM is typically
being used at these times.

This is 3.7GiB of system memory? If that’s system memory, I start to
wonder if this is an odd environment like EC2. If it’s not system
memory, some of it could be virtualized swap space.

and it said that the bug had been fixed. I have not tried my app on
to do that?"
Unfortunately I’m not a Swing expert, and this might not be the right
forum to ask deeper Swing questions. It does sound like the
configuration of your window is propagating events through to the
underlying window.

Your other questions also require Swing knowledge that I personally do
not possess. Maybe others might, or maybe there’s better places to
ask…

  • Charlie

Attached are four thread dumps, performed at start-up, and then every 10
minutes. No other changes to anything from prior post. There are
screencapture photos showing the file diff’s.

Can the heap limit settings be done within the program, instead of as
command line parameters?
I’m running most tests from NetBeans. Plus, it is all running with RVM
managing the “Ruby Environment”. Is there a JRuby “config” file
somewhere that I could place the stuff that would normally go on the
commandline?

As for program “behavior”, other than when there is the conflict as a
result of using the particular website that I mentioned, the program
normally runs just fine. The memory usage grows from 92 MiB at start, to
as much as 160 MiB afer many hours. Mostly it seems to stay around 125
MiB afer a few hours.

I am concerned about the amount of RAM that is being used. The
suggestion of setting a limit on the commandline may be the solution.
However, I am also concerned that I may be using a coding technique that
causes the production of many many duplicate objects. So I would
appreciate any recommendations in that regard.

I am also concerned about interactions with other programs. The conflict
with the web browser, while the browser is working with one particular
webpage, and ultimately crashes both the browser and my JRuby program is
very worrisome. One needs to be confident that their programs don’t
effect other programs. I think that the browser app may be causing the
problem, as it has stopped working before (before I started writing
JRuby apps). But I am still concerned about my app’s stability.

Memory: My computer has 4GB of physical ram installed. The System
Monitor shows that at most, 1.5GB of 3.7GB is being used. I have the
Swap space turned off (swapoff), so physical RAM and the solidstate hard
disk are all there is to work with. (I don’t see a benefit from
allocating a swap partition.)

Regarding the Swing issue, I can live with the JWindow issue (for now).

My real concern is the crashing of my JRuby app when it interferes with
the browser.

Thanks for your help.