Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Memory Leaks in Swing  RSS feed

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are there major memory leaks in correlation to the use of swing components in java programs? Because the project that I am working seems to be eating up mass amounts of memory after leaving the program running for an hour. I am not sure if it is the references to the swing objects that aren't being garbage collected or what the problem is. But whatever it is, it is affecting the performance of the program. Any insight to my problem would be much appreciated.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I too have noticed that a swing based app seems to hog memory. At least the single swing based app I worked on did so. It seems better then straight AWT in performance, but both seem to hog memeory after long periods.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not an expert by far, but I know that the way you cache your data can be memory intensive. Also, if you repeat funtions everytime you do something, i.e. many loops through enumerations for example, can really slow things down. Sorry I don't have an answer for you, but maybe there can be some ways to use softrefereces for caching or limit loops.
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Download the 30 day evaluation version of JProbe and use it on your program. Swing has no memory leaks that I have heard reported. Are you using JDBC-ODBC?
 
Brian Drake
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is one memory leak in swing that I know of offhand: when closing JInternalFrames in a MDI container, the memory from the internal frame is not garbage collected properly. If you have an MDI app and open and close JInternalFrames a lot, you will eat memory...
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think it is exactly a memory leak, but there is a funky behavior associated with strings. The VM pools string references. The result is that going through a loop to append to a string causes the VM to create multiple instances of the string. This sucks memory. The solution to this is to use a StringBuffer for operations on strings until you are ready to use them.
Nick
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!