aspose file tools*
The moose likes Performance and the fly likes Garbage Collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Garbage Collection" Watch "Garbage Collection" New topic
Author

Garbage Collection

Suganthi Velliah
Greenhorn

Joined: Apr 30, 2007
Posts: 17
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.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8997
    
    9

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


[How To Ask Questions On JavaRanch]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12836
    
    5
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
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
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

Joined: Apr 30, 2007
Posts: 17
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
Rancher

Joined: Mar 22, 2000
Posts: 12836
    
    5
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

Joined: Apr 30, 2007
Posts: 17
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.


Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Posts: 489

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)


Sorry, perhaps my english language isn't too good.. Prepare for SCJP 6, Please God help me.. ☼
References : [Java.Boot] [JavaChamp] [JavaPrepare]
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

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.


apigee, a better way to API!
Mark O'Neal
Greenhorn

Joined: Jul 23, 2009
Posts: 5
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: Garbage Collection