Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting a memory leak on ScheduledExecutorService  RSS feed

 
Tom Davis Sr
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying the basic example from the java ScheduledExecutorService API. After a few minutes, I see the memory usage go up. My task has to run for a very long time, hence I am concerned that it could crash the application. Any input would be appreciated.

 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It will be better to profile the JVM and find out what is taking memory, otherwise the memory leak is merely a speculation.
You can use jmap at the minimum to get a dump of the heap and later view it using jhat
 
Tom Davis Sr
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Nitesh. I had this sample program (which really has one print statement to execute every 2 secs) running for 2 hours and I noticed that the memory usage on Windows Task Manager is still going up. I expected it to remain constant after a while.

Is it possible that the JVM would still need more memory after all this time?
 
Chris Hurst
Ranch Hand
Posts: 443
3
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JVisualvm in the bin folder of your jdk is also quite useful, you'll get a "saw tooth" graph as memory rises and if that grapgh has an underlying trend upwards you have an issue.

Just leave it running a long time then look at which objects are using the most memory (string's are always near the top but check what those strings are content wise ... I once found 100Mb's of log file in memory from a Sun bug ..lol) then look for any objects you weren't expecting ;-)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!