• Post Reply Bookmark Topic Watch Topic
  • New Topic

Memory usage in Java App  RSS feed

 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a java app, that seems to use a lot of memory in my opinion. It uses around 50,000K according to task manager. If I close one of the screens, and go back into task manager, it (the mem. usage) doesn't seem to drop at all. I guess my question is what is too much memory usage? What does an average java GUI database app run?

I'm also looking for any tips on why the memory usage doesn't drop when certain GUI frames are closed.
How do I tell if I have objects that are still referenced once that frame is closed? What are the steps I should be taking to ensure that the references are dropped?

Any good references on memory in java would also be helpful. I've been coding for a while, but I'm afraid, not very efficiently.
I'm just starting to figure out I need to look more into the memory stuff. Any help would be greatly appreciated!
Thanks!
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably need to get some sort of profiling tool to help you here (the only one I have any real experience with is Borland's Optimizeit, which is pretty good). You can watch how the JVM is handling object references in relation to garbage collection by using the avaliable Verbose GC options. Have a look on Sun's site, there are a number, but the main ones you could use is -XX:+PrintGCDetails or -verbose:gc. This might give you an indication that there is a memory leak in your code (the heap gets progressively bigger, despite garbage collection).

Explicity trying to drop object references (by signaling them avaliable to the garbage collector) is not often a good route to take. Its quite an involved process, and (IMHO) you shouldn't really be considering it unless you application is pretty complex. Check for memory leaks first. Then you might want to review your code looking for unnecessary object creation (e.g. using Strings rather than StringBuffers etc.)
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that the Task Manager can only tell you the total currently allocated to a particular Java instance by the operating system. Within that allocation, Java creates and discards objects such as the GUI frames. The Java JVM will request more memory (up to the limits you set) when your app needs it, but will NOT return memory to the operating system right away when it does a garbage collection for your released GUI frames, so you won't see that in Task Manager.
Bill
 
nikos sokaf
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When Your application started, then the JVM catches System's memory for it's own.
When i started java, i made a test for memory...
I fill a List with values with an unstopable loop.The List was filled with 100.000.000 (I don't remember the number as it was) values.Then the system crashed.
When i run this example on another pc with 256MB Ram the number of records was pretty smaller.
The JVM gets the memory it want's each time from the system, and parse it to objects.But Java has a Terrific thing... Garbage Collection.No more maloc--(memory allocation) etc.

So take a look for Garbage Collector. I think your application need to be more carefully written , having in *mind* the proper Garbage Collector Usage.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!