Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Garbage Collection

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,


We are facing memory leak problem while running our application. We are using JProfiler to identify the rerason and found the follwing:

1) While making Outer class objects as null it is not getting garbage collected. Since inner classes are referring to Outer class.
How to make the objects garbage collected in this case?

2) We have a lot of Swing Components. They are also not gettiing garbage collected. What could be the possible reasons?

Your response will be very helpful
Thanks in advance.
 
Bartender
Posts: 9612
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

William Brogden wrote:
Does your GUI involve any event listeners?
Improperly disposed of listeners are a prime cause of memory leaks with GUI apps.
Bill



original post here
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

1) While making Outer class objects as null it is not getting garbage collected. Since inner classes are referring to Outer class.



Thats the way it is supposed to work. Inner classes have to keep reference to outer class so it doesn't matter what your program does to the more obvious references. If your inner class was an event listener, bingo!

Bill
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can remove the inner classes from the code and just use regular objects. It sounds like there are a few design flaws that need to be removed.

In regards to the Swing-based components, if there is a GUI to this application, the Swing objects are active while the application is running and shouldn't be collected.







 
Suganthi Velliah
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joe Ess wrote:

William Brogden wrote:
Does your GUI involve any event listeners?
Improperly disposed of listeners are a prime cause of memory leaks with GUI apps.
Bill



original post here



Yeah. Event Listeners are used in the application. How to dispose the listeners? Sorry for questioning you a lot. I am new to Swing thats why
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since it has been years since I used any Swing components, I can only point you to Google, try searching for "swing event listener memory leak"

Here is one discussion I found that way.

Bill
 
Suganthi Velliah
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all !!!

I have written the follwing code and garbage collection is happening properly and memory leakage problem is almost solved.

panel.removelAll(); //(panel is nothing but a JPanel) which removes all the components from the container and dispatches all the events also
panel = null; //After removing all from the panel and making it null ensures the panel to be garbage collected.


 
Ranch Hand
Posts: 494
Eclipse IDE Postgres Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry..

Dear all..

i have a simple question..

how about if we write down : System.gc(); //garbage collection
is the above code can run the Garbage Collector to delete the object which not used in heap memory?..

CMIIW

Thank's
Regards,
W
(Sorry My English isn't too good)
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Leonardo Carreira wrote:
how about if we write down : System.gc(); //garbage collection



The problem here is that there is a memory leak i.e. some objects are not in use logically but are not eligible for GC. This happens if you hold on to references more than required (In simple terms it is a memory leak)
The question here is not whether GC has run or not but even if GC has run the memory is not getting released.
In modern day JVMs. you do not need to indicate that an application is ready for GC (by using System.gc()), JVM in intelligent enough to run GC when required.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

JVM in intelligent enough to run GC when required.


Well..... kinda.

We have a graphical display that displays a road network. When we first designed it, we were only dealing with 50,000 road arcs
to display.

Currently the raw data is over 3,000,000 road arcs. If we let the GC do its thing, when it thinks it should(during load), we were getting
hit with a 40 minute GC delay and the added slow down from entering swap.

If we are proactive and do a gc after ever 100,000 arcs, it loads in 4-6 minutes and never enters swap.


Mark.....

 
I can't take it! You are too smart for me! Here is the tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic