File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Performance and the fly likes Java is consuming to much memory. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "Java is consuming to much memory." Watch "Java is consuming to much memory." New topic
Author

Java is consuming to much memory.

Stephan Freund
Greenhorn

Joined: Dec 22, 2011
Posts: 4
Hello,
My name is Stephan, i´m from Brazil, so first of all sorry for my bad english and thanks alot for your atention!
My problem is that my Java programs are consuming to much memory, let me explain better.
The program is some kind of a Thread responsible for the atualization of my server database, so, it runs continually every 2 hours and never stops. A single loop does not consume much memory, but when I check the memory after 3 days it´s using somethong like 4 or 5 GB of memory.
I suspect that the problem is that the program is not realising it´s used memory and the java memory heap is growing as consequence, I really don´t know what to do, so if you could please help me I would be very, very thankfull.
The program is running in windows 2003 server 64 bits.
The looping part is above:


I´m not a expert, but as long I understand, what is inside a function, only exists inside that function, so the memory should only be "allocated" as long as the function is being runnig. And the same whould be valid for what is running inside the while() { } isn´t it? What´s wrong with my code, please help me.
Thanks alot,

Stephan Freund.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Does anything need to be done? 5 MB is just about nothing for a JVM, the default memory allocation of which is 64MB. So it's possible that the GC has never even kicked in.
Stephan Freund
Greenhorn

Joined: Dec 22, 2011
Posts: 4
Sorry, the correct usage is 5GB not 5MB as I wrote.
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2052
    
  22

When you say "java memory", do you mean the memory used by the java process, or did you actually check the memory used by the heap? If you see memory used by java process growing, it is fine. That's default java behavior. Once java gets memory from the OS it never releases it back. It will maintain it's own memory and allocate new objects in the free memory that it has

If it's the heap that is growing, you will need to get a heapdump and run a memory analyzer to see which objects are growing in memory. Looks like your loop saves some objects in variables outside the threads. Depending on how they are saved, the memory used by those objects may not be released. As long as you have a reference to an object, the object will not be released, even though your thread is complete

I see that the run method in your thread never exits. It looks like it just sleeps for 1 second inside the loop. So, your method will execute once per second, not once per 2 hours. Do you start a thread every 2 hours but none of the threads exit and eventually in a day you have 12 threads doing the same thing?

Stephan Freund
Greenhorn

Joined: Dec 22, 2011
Posts: 4
Well, first of thank you for all your replys.
Sorry for the confusion, let me explain: the thread is called once, and loops "forever".
Every second, the thread will do the following:
Update GUI

Check for manual update solicitation:

Check if last update ocorroured more than 2 hour ago:

obs: tempoFaltando = remaining time to next auto update.

In case of manual solicitation, or last auto 2 hours ago, the program will request
executarAtt(boolean automatico);

Extra infomation:
None of the objects used in executarAtt(boolean automatico) uses Thread nor Static objects, only some static functions, and static final Strings, etc.

I made a memory usage display in my program, and asked 4 times, manually, the program to make a update, and the memory usage after each update was(as atached):

1 update:
Total:1885MB
Used:1161MB
Avaible:724MB

2 update:
Total:2030MB
Used:1067MB
Avaible:963MB

3 update:
Total:2043MB
Used:1222MB
Avaible:821MB

4 update:
Total:2043MB
Used:1516MB
Avaible:527MB


The method to get this parametrs was:


Thanks in adavance.





[Thumbnail for MemoUsage.jpg]

William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12675
    
    5
So you still have available memory

Hurrah! - what is the problem?

It is normal for free memory to change as various objects are created/destroyed and GC runs - if you are not throwing an out of memory error, why worry?

Bill

Java Resources at www.wbrogden.com
Stephan Freund
Greenhorn

Joined: Dec 22, 2011
Posts: 4
William Brogden wrote:So you still have available memory

Hurrah! - what is the problem?

It is normal for free memory to change as various objects are created/destroyed and GC runs - if you are not throwing an out of memory error, why worry?

Bill


Guess you are correct, after 1 day running the memory usage stabilized, and the problem was not with my code but that the program uses more memory as the days go on because the files grow bigger in the end of the month.
Thank you alot for your kindness, case closed!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java is consuming to much memory.
 
Similar Threads
Session is closed
encoding and decoding
parsing incoming socket stream, InputStream.
synchronization.. and threads !!!
poi and protected excel book