Memory leak in java / forcing garbage collection for unused resource?

Is there any possibility in big programs if not designed properly for leakage of memory?
If say i forget to force garbage collection of unused resouces what will happen?
Even if i am forcing garbage collection how much assurity can be given to do so?
I need answers w.r.t typical programming examples if someone can provide i will be happy.
Or any useful link.
Thanks
Vijendra

Memory leaks are usually much related with C/C++ programming since in that language you have direct access to memory using pointers.
Now, in Java you do not have access to pointers, however you could still tie up your objects in a way that the garbage collection can not remove them.
Basically, the grabage collection will search all the object implementation, and see if they are referenced or not. If not it will free that memory. However if you, somehow in you code allow a reference to your object then the garbage collection will not displose of that object.
An example I can think of is when developing web applications. For example storing objects in the session will mean that you will have a reference to the object from the session, therefore the garbage collection will not free up the meomry taken by those objects untill the session has expired.
That is how I know it... at least that is how they tought it to me!
regards,
sim085

Similar Messages

  • Possible causes for memory leak in Java and Tomcat

    I would like to enquire what are the typical mistakes done by programmers that will cause memory leak in Java and Tomcat.

    Please refer the below site. It will give more points about the memory leak and how to rectify it.
    http://www.experts-exchange.com/Software/Server_Software/Application_Servers/Q_20981562.html?cid=336

  • Why can we force Garbage Collection

    Hello,
    Why can we force garbage collection since we have AUTOMATIC garbage collection?

    If you don't call dispose on the Window, it may keep a
    GUI thread running in the background. Since this
    thread is still running and accesible from the root,
    it will hold onto the Window. You should always call
    dipose() on Windows you want to be completely removed.I know I should that's why a mentioned it! But is it correct that I should have to? Nowhere in the documentation does it say so. The fundamental principle is you let go of all object references and eventually the object will be removed by the GC. In this case this important principle is broken.
    At least a clear WARNING should be stated. Window (and all its subclasses) break an important principle of Java. If you don't call dispose your program will leak memory !!!

  • Applescript: force garbage collection?

    Hello
    I am trying to call applescript functions (from my cocoa application - using NSAppleScript's -executeAndReturnError), to automate some operations in Microsoft Word.
    The problem is that after every Applescript call, the Word operates slower and slower (and i guess finally it won't respond at all). I am calling operations, like "set myvar to all words of current document whose [some conditional]" or "set myvar to all fields of current document whose [some conditional]" (which are memory consuming - on each call Word enumerates all the words of a long document, searches there some matches, etc), and i think that after each call of NSAppleScript's -executeAndReturnError, Word doesn't clean its previous "results", which slows it down with every next call. I wanted to try to do an explicit call of Applescript's garbage collector after each -executeAndReturnError from my Cocoa app, maybe that could eliminate the problem i have.
    But i didn't find any info on how to do that. Java, ActionScript - both have System.gc() functions (that launch Garbage collection if it's needed right here and right now). If theres no way to force garbage collecting in AppleScript, maybe someone knows "implicit ways", when AppleScript engine calls it? Like the next iteration of a loop, or some other conditions? Or some timespan, after passing which the GC is called?
    What could cause that slowness of Mac:Word? Is it a mistake of Microsoft, or am i forgetting to do something? If someone could advice readings about how applications usually implement Applescript interface "from the inside" (and who is responsible for cleaning the results of each call), i'd be very thankful.
    Thanks for any advice!
    George

    If you really want to see the results you should also run the finalizer
    thread on the newly garbage collected objects. It might take up to 2 GC
    cycles for the memory to be actually free for new allocation at least on
    the Sun JVMs. Maybe the new types of garbage collectors do it better or
    more optimized but anyway, the GC would first mark the objects and only
    then the finalizer will run to call the finalize method. Then next GC
    will free the memory of the finalized objects.
    HTH,
    Dejan
    Dinesh wrote:
    Hi Slava Imeshev,
    Thanks for immediate response. I agree JVM will do GC at specific interval. But,
    I have found that , there is some difference in both of them. If you invoke "Force
    Garbage Collection" explicitly, the graph will show the heap memory usage to baseline.
    Where in, if you perform System.gc(). It won't make much difference.
    Thus why, I want to know what is the code behind the "Force Garbage Collection"
    button.
    Thanks,
    -Dinesh.
    "Slava Imeshev" <[email protected]> wrote:
    "Dinesh" <[email protected]> wrote in message news:406a8df4$[email protected]..
    How can i schedule "Force Garbage Collection" to be done at every
    week or daily?.
    Can i automate this process instead of manually invoking the button?
    GC is already done by JVM automatically.
    Why would you want to "schedule" it?
    Regards,
    Slava Imeshev

  • Do you think JOptionPane dialogs force garbage collection afterwards?

    I ask because I've made a nested static class to implement my own file selection tool; the problem is that each time I call it the old JPanel is being recalled and so the components get re-added to it each time it's called, resulting in n versions of each file for every n times you open it.
    I'm running myDialog.dispose() upon exiting, so is my only option now manual garbage collection? How could I force it to be garbage collected? Because System.gc() seems to have no effect.

    Strictly speaking there is no way to force garbage collection, so, no, JOptionPane will not be doing it.
    You almost certainly have a leak in your code. Post it and we may be able to help.

  • Memory Leaks in Java

    Hi,
    I have a considerably large business application that consists of JSPs and JavaBeans which connects to a database. The application runs off a Tomcat server. Some information about the application is as follows:
    a. JDK version 1.4.2_11
    b. Database used is MS SQL Server 2000 with Server pack 4
    c. Running on Tomcat version 4.1.31. Tomcat is being run under services.
    d. Third party libraries -
         Cryptix32
         i-Net Crystal Clear
         CeWolf and JFreeChart
         iText
         jxl
    I noticed that the Tomcat memory utilization increases after a period of using the application.
    I recently purchased JProbe as it was recommended as a good tool to check for memory leaks in Java applications. Having purchased Jprobe, the team is now proceeding to investigate the cause of the problem.
    I would like very much to seek the expertise of the community here as to some technique / steps the team should take during the course of the investigation.
    We are currently following the following steps:
    a. Startup JProbe
    b. Set a JProbe J2EE memory session which points to Tomcat and JDK
    c. Run the JProbe session
    d. Do a Collect Stack Trace
    e. Login to our application, execute a "single function" and then logout
    f. Do an Include Heapdump in Snapshot
    g. Save the snapshot
    h. Stop the JProbe session
    i. Investigate the output
    j. Repeat (c) to (i) for other functions in our application
    Would appreciate if the community here could advice if we are proceeding with the investigation correctly and whether we are missing out on any memory leaks. All suggestions are most welcome.
    Thanks.

    Hi,
    Just a bit more information about the application:
    Application contains:
    - 4490 JSP files
    - 1492 Java Classes
    Application Server:
    - Tomcat 4.1.31
    - JDK 1.4.2_11
    Database:
    - Microsoft SQL Server JDBC 2000
    - Microsoft SQL Server 2000 SP4
    Other JAR files:
    - Cryptix 32
    - jxl
    - CeWolf
    - i-Net Crystal Clear
    All items mentioned above is running on a Server with Microsoft Windows Server 2003 with 2GB of RAM.
    The JSP communicates to the JavaBean which in turn will connect to the Database via JDBC. We are not using connection pooling at the moment.
    The SQL Server takes around 1GB of ram and I have configured Tomcat with an Initial 250MB and a maximum of 750MB of RAM. Tomcat is running under NT services.
    Tomcat memory slowly increases and it takes around 4-7 weeks before it reaches the maximum memory and we get the out of memory error.
    We have done checking for memory leaks using JProbe but have not found any leaks in our program yet. We did find some of our classes were not closing the connection. I am not sure whether this could be the cause of the memory leak. We have also checked for static members in our classes and have not found anything wrong with them.
    Can anyone tell me whether:
    a) Is 2GB RAM sufficient for this type of configuration?
    b) If we add more RAM will it be more beneficial?
    c) Our Tomcat web.xml configuration. Reloadable = true, Development = true. Will this cause memory leaks?
    d) Should we upgrade to Tomcat 5 or 6?
    e) Should we upgrade the JDBC Driver to 2005?
    f) Should we upgrade the version of JDK to 1.5 or 1.6?
    g) Is it recommended to restart Tomcat every now and then?
    Thanks.

  • Force Garbage Collection through scripting

    Hi ,
    I am using weblogic server 8.1.5 on windows 2003 server.
    can we do force garbage collection through a script? If so can i have a sample script for the same?
    OS:windows 2003 server
    thanks in advance.
    Madan Mohan

    And the key here is "any length of time". I used to have WLDF notification on for all errors in the log file, but I specifically disabled it for the "almost out of memory" error, because it happened constantly, even when we didn't really have a memory problem. It's a little harder to determine the "any length of time" constraint. I'm not aware of an interface to "gc()" through WLST, which would be the most practical way to do this.
    I think it's possible the "shape" of your free/used memory patterns would change if you changed your GC algorithm. If you're currently using a "stop the world" collector, the free memory percentage will probably decrease almost to zero before it collects. However, if you use a generational collector, it's possible in normal operation that you won't get down so close to zero before it collects. In that case, the "almost out of memory" error might be more meaningful.

  • Memory Leak in  Java

    Anyone can suggest what is the best way to test memory leak in JAVA?
    Thanks in advance for the help.

    I'll try to define it for the OP
    Define: memory leakhttp://en.wikipedia.org/wiki/Memory_leak
    Define: bestDoesn't really apply but wondered what wikipedia would return: http://en.wikipedia.org/wiki/Best
    Define: testhttp://en.wikipedia.org/wiki/Software_testing

  • About Memory Leak in JAVA Any body pls help me

    Hi All,
    In our application, with JAVA we are using c, c++ native methods also.
    The problem is, Eventhough the application is in idle state, the Virtual Memory occupation is getting increased. For 24 hours, 30 MB is increased, while the application is in idle state.
    Is there any possiblity, this much memory leak can happen in JAVA. or it is from Native c side..
    I would appreciate anybody' s help.

    Thanks
    I am using JProfiler for that. I can observe what kind of objects not getting freed and the size of memory it is taking. and i observed thro JProfiler, that is only 16 kb of memory leak is happening. Can Any body who is well known about JProfiler help me. Can i differentiate the memory leak from JAVA and Native C side using JProfiler.
    Any help would be appreciated.

  • Force Garbage Collection

    Before I load a new level, should I force garbage collection on the old level? And if so, how?

    Just remember that the method suggest the garbage collector to run, not forcing it..
    If you have a lot of objects created that are later available for garbage collecting, you could try to reuse the objects instead of creating new ones (if garbage collection is really a problem for you).

  • Force Garbage collection externally....

    hi!
    I am new to java.is it possible to the force Garbage collection externally?
    can i achieve it by giving the command "System.gc();".pls give me idea...
    Thanx
    Rgds,

    You can't force a full GC as far as I know. gc() might force a GC of the youngest generation.
    Why do you think you need to force it?

  • Huge memory leak in java jvm after update 2 for Snow leopard

    Since I updated to Java Update 2 for Snow Leopard my JVM suddenly grows massive (10GB+ real memory - -Xmx=3500m) consuming all memory and rendering my iMac unusable. This does not happen predictably but does happen several times a day now requiring I power off and on again.
    I had been living happily with update 1 with no such problem.
    I need to either go back to update 1 (should have it on Time Machine) or find a solution for this problem.

    Our application is a j2ee-based commercial application facing to specified customers, having about 120 access request an hour.
    We ' re doing stress test on the test server. The strange memory leak occurs at 1:20 am this morning while we're out of company , and no job was scheduled to run at that time. So I have the tendency to image that there is something inside oc4j had occured.
    I have used OptimizeIt to monitor the heap status. However , as the memory leak problem occurs very occasionally ,and that tool deadly slows our server, we are currently using no profiling tools.

  • Memory Leak in Java Server

    Howdy Folks- I wrote a server monitor in java, which I was expecting to run for months at a time without restarting. Apparently there is some slow memory leak which results in an OutOfMemoryError after a few weeks. It's in a production system, so I can't readily add debug statements to the code, and the OutOfMemoryError apparently screwed up the logging, so I didn't get a stack trace in my logs, just an "OutOfMemoryError" went to standard out.
    I'm assuming the problem lies in the code, specifically probably some discarded reference that is not being properly garbage collected? I am using a few different ArrayLists to store some historical information, and I call clear() on these frequently. Is there any known issue with ArrayList or HashMap that the "clear()" method doesn't result in garbage collection of the objects that were in it? I am also doing a "remove(int)" sometimes as well. Any chance the objects cleared or removed would not be garbage collected?
    thanks
    Bleu

    Howdy Folks- I wrote a server monitor in java, which I
    was expecting to run for months at a time without
    restarting. Apparently there is some slow memory leak
    which results in an OutOfMemoryError after a few
    weeks. It's in a production system, so I can't
    readily add debug statements to the code, and the
    OutOfMemoryError apparently screwed up the logging, so
    I didn't get a stack trace in my logs, just an
    "OutOfMemoryError" went to standard out.Are you even attempting to catch Errors? Catching Exceptions will not help with this. It should print the stack trace. When it OOMs it doesn't mess up what's already allocated, it just can't allocate more.
    I'm assuming the problem lies in the code,
    specifically probably some discarded reference that is
    not being properly garbage collected? Most likely, there are references that are never being cleared in your code. Without seeing the code or at least having a better description, I don't think anyone here can help you. Can you set up a test senario and use an Optimizer to see what's going on?
    I am using a
    few different ArrayLists to store some historical
    information, and I call clear() on these frequently.
    Is there any known issue with ArrayList or HashMap
    that the "clear()" method doesn't result in garbage
    collection of the objects that were in it? Not that I know of, no. I doubt that is the problem.

  • Howto Force Garbage Collection manually in Oracle Application Server

    Hi,
    I have a Oracle SOA suite installed on Oracle 10g Application Server. The heap memory for the SOA oc4j container is 2G with a permgen space of 256M. But it looks like there is some memory leak somewhere and the Heap area is getting filled frequently and this causes an *[libopmnoc4j] OC4J ping attempt timed out* and as a result of this the SOA oc4j container gets restarted automatically.
    Is there any means by which we can force a Garbage Collection manually so that this automatic restart does not happen.
    Kindly let me know if it is possible to trigger a Garbage Collection manually in Oracle Application Server.
    Thanks,
    Vijay.

    We had a similar situation where the oc4j instance will throw OutOfMemoryException and opmn will restart a new instance every 10-12 hours. The JDBC 10.2.0.3 driver has a memory leak in the XA Resource classes. There is a fix available in metalink.

  • What is memory leak in Java context?

    I am looking for a precise definition here...

    If you are looking for HOW a memory leak can show up in java, here are a few examples:
    A stack implemented on an array can have a memory leak if the object's position in the array isn't set to null after the object is popped off the stack (I think I first saw that in "effective java", by joshua bloch, if you want to look more into that).
    Another way: interning strings to the jvm can cause a memory leak, because once a string is interned, it is stuck there forever, even if all other references to the string are gone, and the string will never again be used.
    Furthermore, any flyweight concept that doesn't have a strategy for pruning away unused object (objects with 0 external remaining references) will be a memory leak of a sort.
    Hash maps are another place you can run into this problem. They may hold the only reference to both objects of a pair, and hence, since the key exists nowhere else, the pair is basically useless, but the map does prevent them from being garbage collected.
    What's the common link? The all have to do with some data structure or another maintaining obsolete references to objects. Since objects can't go out of scope if they are stored in a data structure that doesn't go out of scope, they cannot be garbage collected.
    - Adam

Maybe you are looking for

  • Satellite A205: Dynadock - How to connect to LCD TV with HDMI to DVI cable

    I recently purchased this product and had a problem when connecting it to my LCD TV. I used a HDMI to DVI cable to connect it to the TV. Only a small portion of the full display shows on the TV. I have adjusted all setting on the laptop (Satellite A2

  • How Do I Get My Laptop to Use My Desktop iTunes Library?

    My desktop iMac has an external HD where my iTunes library lives. I just got a MacBook and would like to have the laptop access the same iTunes library. The MacBook uses airport WiFi off my router, the iMac is wired to the same router, the external H

  • Problem using associative arrays in vb6 with ORAOLEDB for Oracle 10g

    The following vb6-code works fine with MS OLEDB (in MDAC 2.8) but not with Oracles OLEDB for 10g. Any suggestions for making it work? 'vb6-code: Set rs = New ADODB.Recordset Set rs.ActiveConnection = oConn 'oConn is already initiaded - code not inclu

  • Help in Freq Modulation and demodulation

    Hi, I was asked to design Frequency modulation and demodulations without using modulation tool kits. I some how managed to construct frequency modulation, i also got the output. But if the graphs are observed, we can c that message signal is in betwe

  • BAPI that contain user IDs , passwords

    Please let me know if there is any BAPI or RFC that contains the user information like user IDs, passwords etc. I need that to use in the XI. I am using SAP system as the target system or the source system . Thanks kanan