2

Am working on a swing app. I will experiance slowness after continuous half an hour of use.

can it because of GC running?

How can i find when the garbage collector runs through any jdk 1.5 commandline option?

Thanks

1
  • 1
    This looks like symptoms of memory leakage (which is hard to track at times in java) Commented Jul 16, 2009 at 10:48

7 Answers 7

9

When you start Java with -XX:+PrintGC, it will print messages whenever it garbage-collects.

Sign up to request clarification or add additional context in comments.

Comments

6

You can use jconsole.exe, which can be found in the bin directory of your jdk. It shows you a lot of details about your running JVM.

1 Comment

+1 for jconsole. You'll see a saw tooth graph of memory usage, showing when the GC's kick in. You can even trigger a manual GC if you like. I doubt you'll find this is GC rlated though.
4

It's highly unlikely that the GC is causing observable problems. Once upon a time Java had a horribly slow GC that gave it a near-permanent bad reputation. That time is past.

What exactly is the slowness? A GC should really never take more than a fraction of a second, even for the rare full collection pass.

Edit: Even if the GC is running a measurable amount, it's likely only a symptom of the problem. Whatever code is placing that much demand on the GC would internally cause more slowness than the GC will.

2 Comments

This is only true for small applications, which might be the case here. As soon as you scale up memory usage and therefore GC can easily become a problem. In most cases it is more about the number of garbage collections that about the time it takes a single GC.
If by small you mean less than a gig or two, then maybe?
3

The simplest way to investigate this if you use recent JDK is jvisualvm which allow you to attach to a running process. You can then see garbage collections, memory usage and profile if needed. (It is essentially the corresponding NetBeans functionality available as a standalone applciation in the JDK).

It complements and enhances jconsole!

(But what you describe may be excessive GC's caused by a memory leak in your program. Use jvisualvm to figure out)

Comments

2

I strongly doubt it's the GC you are seeing. As 280Z28 points out, the GC runs pretty fast usually (though can still kill performance if you're doing something wrong). Are you using the program in that time? If not, maybe you're a little low on memory and it got paged out? (leaving Eclipse running for longer than maybe half a day without using it results in a state I can't work anymore with it. On systems with little memory it might happen sooner).

Comments

2

GC itself probably is not the problem. However, if you have a memory leak, it might result in GC using all CPU trying to clear memory.

Comments

0

As everyone has mentioned previously, GC is almost certainly not the problem.

I'd try something like YJP (Your Java Profiler, free for 30 days) to profile your application and find out what is slowing down. A memory leak is a very possible cause.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.