Re: JLabels Are Big
Jason Cavett wrote:
I did a little more research. As you have said, 20 labels isn't big
and doesn't really affect anything. But, when I get upwards of 100+
labels, I notice a pretty big slowdown. Even then, my JLabels are
~419 bytes in size and, while that is somewhat big, it's not THAT big.
I guess I'll start doing some memory profiling to find out where
memory is being used up and what's causing the problem.
You may have lots of previously made objects (labels) laying around
taking up memory, and the gc is thrashing trying to find new memory to
allocate. If something is holding a reference to those old labels,
they'll not be available for garbage collection.
When you profile, turn on both object creation and garbage collection
monitoring (under "Memory"). That way you'll have the data you need.
I'd also turn on Thread Monitoring (under "Monitor") because it sounds a
bit more like you have a run-away thread or something.
Look at the "generations" column of the memory allocation display.
Objects that survive many generations of garbage collection are possibly
leaking. If you should have 100 labels but there are 10,000 in memory
being held, you definitely have some sort of leak. Looking at the
generation number might help you figure out where the leak is. You may
have to turn on stack tracing for object creation to figure out exactly
where this is.