Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java memory performance - strange behaviour (or is this normal?)

Hi there I would like to start by saying that i'm a beginner, but i'm working on a really small and simple Java app, that really shouldn't cause some major problems. I was monitoring memory usage from windows task manager, and noticed that with my application started, java.exe was using about 70MB of available memory. So I thought to myself, ok, this probably is a little large, but still, nothing that my PC couldn't handle. But really strange thing started happening when i tried to resize my window, memory usage suddenly jumped to like 80-90 MB, and if i would continue dragging my window, randomly resizing, it kept increasing memory usage. I thought it has something to do with calling repainting methods on GUI components during window resize, so i took a few suspicious components that could cause some kind of memory leak, and deleted those from my mainwindow form, leaving my program almost completely stripped down, but this issue persisted. What i noticed later was that if i keep resizing my window, memory usage grows up to 200-220 MB, and then stops this uncontrolled growth there. So can somebody tell me, could this be a normal behavior having in mind memory management in java?

like image 588
Kani Avatar asked Jun 06 '11 07:06

Kani


1 Answers

Java objects created are not necessarily cleaned up once they're finished with. Instead, something called the "garbage collector" periodically runs in the background looking for orphaned objects and deletes them, freeing up memory.

Your application is likely creating lots of temporary objects as it resizes your window. Although no longer being referenced by anything (ie orphans), these objects are hanging around until the garbage collector runs.

You'll probably find that your max memory is 256M (the default) - the garbage collector is probably being called more often as you approach your max memory and the creation of new objects requires memory to be freed up immediately - hence the memory hovering just under 256M as the creation/deletion rate is balanced by demand.

This is completely normal behaviour.

like image 65
Bohemian Avatar answered Oct 11 '22 19:10

Bohemian