?
Solved

Memory Leakage - Is "System.gc()" good to help solve this?

Posted on 2003-03-10
18
Medium Priority
?
241 Views
Last Modified: 2013-11-24
Hi,
I am having a lot of memory leakage problems with an EJB developed web site which runs on a JRUN 3.1 application server.
I wondered do you know if using "System.gc()" is a good wayt to help solve memory leakage problems and if so, then would I have to implement it in every Java class (seems a bit of a pain to have to do) or can I just write a class which uses this method and takes care of memory usage for the whole application server?

Any help on this or any ideas would be greatly appreciated.

Cheers.
0
Comment
Question by:gusboy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 4
  • +3
18 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 8101894
No, not really. You'll have to get to the root cause of the memory leak. Have a look at some profiling tools. Unfortunately i've never used any.
0
 
LVL 35

Expert Comment

by:girionis
ID: 8101950
 There is a realyl interestign article on JavaWorld: http://www.javaworld.com/javaworld/jw-03-2003/jw-0307-j2segc.html about memory leakage and different versions of garbage collector, although as CEHJ pointed it's better to identify the source of the leakage (if any) in your application.
0
 

Author Comment

by:gusboy
ID: 8102471
Here's a weird point which some of you might be able to explain.

In My Windows Task Manager programme. I monitor the memory levels used by my Java processes.

My web site was running Javaw.exe processes, but I've now changed to run a java.exe.

I leave the java.exe process running in a dos window on my web server.

If my memory levels are high for my java.exe process. Then If I minimize my dos window (where my java.exe is running) and then maximize this window again, my memory levels drop from my java.exe in my Task Manager processes.

Can any of you explain why this happens. I am currently using this manual way to keep my memory levels low. Does minimising my dos window comehow initiate Garbage Collectioj, and if so is thee some way I can program this to happen automatically?
0
Automating Terraform w Jenkins & AWS CodeCommit

How to configure Jenkins and CodeCommit to allow users to easily create and destroy infrastructure using Terraform code.

 
LVL 35

Expert Comment

by:girionis
ID: 8102545
 Not sure why this happens. It could be that Windows put the java application on the background and give a greater priority to the application that's currently active.

  Not sure though if Windows work with pre-emption or with time-slicing mechanism. I *think* it's time-slicing so not sure why it's happening.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8102574
>>Not sure though if Windows work with pre-emption or with time-slicing mechanism.

The former. You shouldn't really approach this problem by trying to 'paper over the cracks' gusboy. You should get to the source of the memory leaks.
0
 
LVL 2

Expert Comment

by:warsql
ID: 8103307
What makes you think there is a memory leak?  
0
 

Author Comment

by:gusboy
ID: 8103357
I think there is a memory leak because the memory levels keep rising for java.exe in the Task Manager processes, and don't seem to release the memory at all unless you force it to do so by minimising the dos window and then maximisisng it again.
0
 
LVL 2

Expert Comment

by:warsql
ID: 8103452
Are you using -ms or -mx when starting these apps?  If not, the default maximum heap size for a java app is 16 megs each.  This is not the maximum amount of memory the app will use, but it is a major factor.

The reason I asked is because I can't think of how anything the operating system does could 'solve' a memory leak.  By definition a memory leak cannot be recovered from short of a restart of the application.
0
 
LVL 35

Expert Comment

by:girionis
ID: 8103502
 Why don't you try a tool like optimiit and see if somethign goes wrong with your application? You can download a trial version from here: http://www.optimizeit.com/app/download/downloadArea.jsp
0
 

Author Comment

by:gusboy
ID: 8103841
warsql - I'm not really sure which is used to be honest. How do I check?


girionis - I have downloaded optimizeit so going to try and implement it now.

0
 
LVL 2

Expert Comment

by:warsql
ID: 8104014
If you are using a script to start the app, look at the line that starts it or at the echo to the dos window.

java -cp classpath JRunServer(or whatever its called)

If you are using memory args you will see

java -Xms 32m -Xmx32m -cp classpath ...

or something like that.  If you don't see -Xms or -Xmx, then it is using defaults.  Try setting these to control memory heap usage.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8104360
Messing with the heap size is also papering over the cracks
0
 
LVL 2

Expert Comment

by:warsql
ID: 8105647
How do you know there are cracks?  If there truly is a memory leak, then it would crash when it runs out of memory.  I haven't heard that this is happening.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8105871
Well, i was *told* there are memory leaks. You might be right - it could be just memory-intensive, but this has to be investigated.
0
 
LVL 1

Expert Comment

by:jcaldwel
ID: 8105915
System.gc() "Suggests" to the VM that it should devote some resources to garbage collection... in other words it does very little.

Be careful of anything you put into a map or collection. (General good Java practice).

EJB Can be very memory intensive. Especially with Entity beans. Be careful of query sizes in your "findBy" methods. These can chew up your stack pretty fast.
0
 

Author Comment

by:gusboy
ID: 8110072
Cheers all fot the help on this.
I'm trying to get optimizeit to work to see if any areas are more memory intensive than others.

I hadn't realised that Entity Bean "findBy" methods use up so much stack also.

CEHJ - you say that it may not be a memory leak and may just be memory intensive. The reason I thought first of all that it was a memory leak was because it does not seem to be releasing the memory even after a long period of time.
Could there be some other explanation for this other than a leak?
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 600 total points
ID: 8110394
>>Could there be some other explanation for this other than a leak?

Yes, several, one of which can be objects that are no longer being used are still hanging around. This is one reason why the concept of leaks in Java can be misleading. Let us know how you get on with optimizeit.
0
 

Expert Comment

by:SpideyMod
ID: 8585258
Administrative Action - Force Accepted

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month8 days, 16 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question