0

I'm running a JavaFx Application using Netbeans 8.2. When the application is initialised, I click on the application menu to open a file, which pops up the file chooser window. Now, this is where the problem happens. When I look at the memory usage in the System Monitor (on Ubuntu 16.04 LTS), the java memory usage keeps on increasing (see image) every few seconds until I cancel the file choose window.

I ran the profiler in netbeans to get some insight, but everything seems fine. Even heap usage is within limits. Not sure what the issue is.

Memory Usage Screenshot

Ulkurz
  • 73
  • 1
  • 10
  • Are you having an actual problem? Are you getting errors? Or is the issue just cosmetic with a number being displayed that makes you unhappy? – David Schwartz Apr 28 '17 at 00:10
  • @DavidSchwartz - well, if the memory keeps on increasing, the application eventually hangs. So yeah, that's the problem. – Ulkurz Apr 28 '17 at 00:13
  • Okay, so the actual problem is that the application is hanging? And you think it's hanging because of the increasing memory utilization? Or have you confirmed this somehow? – David Schwartz Apr 28 '17 at 00:14
  • @DavidSchwartz - yes, cuz my system memory is 16GB. So in the situation explained above, if the java memory keeps on increasing till the point it reaches the system memory, the application hangs. – Ulkurz Apr 28 '17 at 00:21
  • @Ulkurz You are comparing apples to oranges. Your system memory is physical memory. The utilization is virtual memory. Systems can produce much more virtual memory than they have physical memory. – David Schwartz Apr 28 '17 at 00:51
  • 1
    Probably the best bet here is to create a short, complete example (a [MCVE]) that actually runs out of memory, and post it in your question. – James_D Apr 28 '17 at 01:05
  • Do you limit the heapsize of your app when starting it? Start it with for example -Xmx512m and see if this enough to keep it running. – P.J.Meisch Apr 28 '17 at 05:28
  • 2
    What X and mesa versions do you have installed? You may be seeing [this issue](http://stackoverflow.com/questions/40228866/optimizing-memory-leakage-in-javafx/40239829#40239829) – Itai Apr 28 '17 at 06:25
  • Just thinking if the initial directory for the filechooser is having large number of files. Try setting a custom directory with a few files as initial directory using filechooser.setInitialDirectory() – RajatJ Apr 30 '17 at 04:05
  • @RajatJ - actually that shouldn't be an issue cuz the application runs just fine in the windows environment. – Ulkurz May 02 '17 at 16:51
  • I think file chooser probably uses native code in the backend which is implemented differently on different platforms. You may just try out my suggestion to verify my speculation – RajatJ May 02 '17 at 18:37

1 Answers1

0

Don't worry, it keeps climing up but it eventually gets cleared back down when it does a GC (Garbage Collect). I've noticed that too (also from Netbeans 8.2), which brought me to here.. But then while I was typing, I noticed it drop back down and I was like "Ohhhh, the GC just happened".

It's true JavaFX could probably reuse some objects, but I've noticed for me it doesn't add more than 100MB of RAM, and then collects and resets back down.

You can limit the amount of max RAM you want it to allocate as well so it garbage collects earlier. :)

To set the min/max RAM, go to Project Properties -> Run -> VM Options and put -Xms16M for minimum, and -Xmx400M for maximum.. M/G for Megabyte and Gigabyte..

Example:

-Xms16M -Xmx400M

Raid
  • 747
  • 8
  • 17