Finding memory leaks in java

Hello,
I have a memory leak in my application. I have found other memory leaks in the software using JProfiler, but I have a problem with JProfiler finding this one. My biggest problem is the JProfiler itself. If I use short runs, the JProfiler works fine. If I run my application for more than half a day, the JProfiler eats up memory and after a while it stops responding.
I tried JProbe, but after profiling my application for 18 hours straight, it got buggy and wouldn't work correctly. It also ate up alot of memory, and couldn't process my snapshot after 18 hours of run. I saved all snapshots, and restarted JProbe. The initial snapshot was read correctly, but the final snapshot threw an NegativeArraySizeException.
So, now I am looking for other tools which are able to find memory leaks without hanging or crashing after running 24 hours. Any recommendations?

I dont know any other profiler you can use, but how about using the divide and conquer approach?
Disable a significant section of your application and let it run for a day. If the leak occurs, its in the non disabled part.
If it doesn't, its in the disabled part. Next, enable all the code. Then disable about half of the half that failed and try that. Continue doing so until
you isolate the code enough that you can look at it and hopefully find the problem. Note you will need to keep track of what you previously enabled and disabled as a test (I put comments in the code).
Alternately, you can look at functions that perform complex functionality that you suspect might be the problem and have the function return
dummy data rather than perform the functionality. If the leak goes away, its that function(s).
Example:
public String getComplexData(String arg1, String arg2){
//this section bypasses the complex code and returns dummy data
boolean x1= true;
if(x1==true)
return new String("some dummy data");
//complex functionality goes here.
Also of help would be to list everything that can cause a memory leak (I assume its a memory leak and not a resource leak such as not closing connections).
Here are some ideas:
1) persistant class variables that are a collection that have objects added to them but never deleted and allowed to be garbage collected
such as static class variables, session scope variables, or application scope variables.
2) An object tree where one of its nodes is never set to null to be garbage collected (such as a static class variable).
If you are running a web application in a clustered enviornment, try running it on only one server.

Similar Messages

  • 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.

  • 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

  • Find memory leak

    Hi All ,
    In our SAP application server (Solaris 10 X86 running on hardware HP ProLiant BL685c G5) physical memory available is day to day decreasing drastically. We suspect, there is a memory leak.
    Could you please let us know how to find memory leak in Solaris.
    Regards,
    Rajesh.

    Hi Rajesh
    Memory leaks have a large number of possible causes, including:
    •Unsupported hardware or software
    •Custom Scripting
    •Misconfiguration
    •Third party hardware and software issues
    The prstat command can be used to gather basic performance data to help identify if there are any processes consuming a large amount of memory. For example, the data below is sorted by the SIZE column. SIZE is the total virtual memory size of the process:
    prstat -s size
    If you are experiencing some of the symptoms described above or if you suspect a memory leak, it is particularly important that performance data is captured so the memory leak can be confirmed. It is important to gather at least the following pieces of information:
    •Process ID (PID)
    •Size of the process
    •The executing command
    •The timestamp information showing exactly when the data was captured.
    while true
    do
    for pid in `cat pids`
    do var=`date|cut -d' ' -f4`
    echo "$var :\c" >> ps.log.$pid
    ps -eo pid,vsz,rss,pcpu,args | grep $pid |grep -v grep >> ps.log.$pid
    done
    sleep 30
    done
    You could check the memory utilisation details through
    #mdb -k
    ::memstat
    kmastatRegards
    Sadiq

  • 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

  • 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.

  • Finding Memory leaks in C using Visual Studio 2013

    I am using Visual Studio 2013, and taking a course in C programming and we started
    talking about memory bugs detaction, in particular memory leaks, and how to detect them using Valgrind on Linux.
    I want to know if there is a way to detect such memory leaks using VS 2013. I tried searching online but it just leads to lots of articles and blogs and msdn posts and blogs with lots of words like dump files, and analyzing them, etc which is weird
    because:
    1) It sounds so complex, convoluted and unintuitive it is actually hard to comprehend it.
    2) The main reason this is weird is due to the fact that VS is the most advanced IDE around and Microsoft spends so much money on in, yet from what I have read it seems that there is no simple way to use VS to detect memory leaks
    - certainly no way that's as simple as Valgrind where I only have to compile the program and run the command valgrind -leaks-check=yes ProgramName
    and it simply prints to me all location it thinks there is a memory leak and describes the error (like not freeing memory after allocating it with malloc hence having "dead" memory after the program finishes, or accessing memory that's out of
    the array bounds)                                                                                                                                                               
    So my question is how to use VS 2013 in order to achieve the same results and to find out First in high level if there are memory leaks in the program, and Second - to detect in a simple manner where those leaks are- preferably without involving dump files
    (not that I know how to use them anyway in VS).

    Hi MicrosoftLaw,
    Thanks for your post.
    Based on your issue, if you want to check if there are memory leaks in the C program from this VS2013. I suggest you could try to find Memory Leaks Using the CRT Library, for more information:
    https://msdn.microsoft.com/en-us/library/x98tx3cf.aspx?f=255&MSPPError=-2147217396
    In addition, I find a similar thread about this issue, please you refer the Dusty's suggestion to check this issue.
    http://stackoverflow.com/questions/45627/how-do-you-detect-avoid-memory-leaks-in-your-unmanaged-code
    I did some research about this issue, I found that the Visual Leak Detector extension tool is a free, robust, open-source memory leak detection system for Visual C++. So if possible, I suggest you could try to use the Visual Leak Detector extension
    tool to find the memory leak for Visual C/ C++ program.
    https://visualstudiogallery.msdn.microsoft.com/7c40a5d8-dd35-4019-a2af-cb1403f5939c
    However, if you have any issue about how to use this Visual Leak Detector extension tool to find the memory leak for C program. I suggest you could directly to write a review to this REVIEW tab in Visual Leak Detector site.
    Best Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • 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.

  • Finding Memory Leak

    Is it possible to find the memory leak using the following command
    java -Xprof <classname>Regards
    ackumar

    Here is the output for one of my class. I didn't use any "java.net" class in my code.
    But it shows java.net.SocketInputStream.socketRead() is interpreted 50.0%
    I am in bit confusion . So plz help me.
    Flat profile of 93.41 secs (4041 total ticks): main
      Interpreted + native   Method
    50.0%     0  +  2012    java.net.SocketInputStream.socketRead0
      0.0%     0  +     1    java.lang.ClassLoader$NativeLibrary.load
      0.0%     0  +     1    java.net.SocketOutputStream.socketWrite0
      0.0%     0  +     1    java.lang.ClassLoader.defineClass0
      0.0%     0  +     1    sun.misc.URLClassPath$7.getInputStream
      0.0%     0  +     1    com.mysql.jdbc.SingleByteCharsetConverter.<clinit>
      0.0%     0  +     1    com.mysql.jdbc.MysqlIO.checkErrorPacket
      0.0%     0  +     1    com.mysql.jdbc.Connection.<init>
    50.2%     0  +  2019    Total interpreted
         Compiled + native   Method
      0.4%    15  +     0    cern.colt.matrix.impl.DenseDoubleMatrix2D.zMult
      0.2%     7  +     0    java.lang.FloatingDecimal.readJavaFormatString
      0.1%     4  +     0    com.mysql.jdbc.ResultSet.getString
      0.1%     0  +     3    java.lang.String.<init>
      0.1%     3  +     0    com.mysql.jdbc.SingleByteCharsetConverter.toString
      0.0%     2  +     0    cern.colt.matrix.impl.DenseDoubleMatrix2D.getQuick
      0.0%     2  +     0    com.mysql.jdbc.Buffer.readFieldLength
      0.0%     0  +     2    java.io.BufferedInputStream.read1
      0.0%     1  +     1    java.lang.FloatingDecimal.doubleValue
      0.0%     2  +     0    java.lang.Integer.parseInt
      0.0%     1  +     0    java.util.ArrayList.get
      0.0%     1  +     0    java.util.HashMap.hash
      0.0%     1  +     0    com.mysql.jdbc.MysqlIO.readFully
      0.0%     1  +     0    com.mysql.jdbc.Connection.getCharsetConverter
      0.0%     1  +     0    com.mysql.jdbc.ResultSet.getInt
      0.0%     1  +     0    cern.colt.matrix.impl.DenseDoubleMatrix1D.assign
      1.2%    42  +     6    Total compiled
             Stub + native   Method
    48.3%     0  +  1943    java.net.SocketInputStream.socketRead0
    48.3%     0  +  1943    Total stub
      Thread-local ticks:
      0.4%    18             Blocked (of total)
      0.0%     2             Interpreter
      0.3%    11             Compilation
    Flat profile of 0.01 secs (1 total ticks): DestroyJavaVM
      Thread-local ticks:
    100.0%     1             Blocked (of total)
    Global summary of 93.43 seconds:
    100.0%  4127             Received ticks
      2.1%    85             Received GC ticks
      0.0%     2             Interpreter

  • 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.

  • How to root out memory leak with  Java JNI & Native BDB 11g ?

    We are testing a web application using the 32-bit compiled native 11g version of BDB (with replication) under 32-bit IBM 1.5 JVM via JNI under 64-bit RedHat Linux. We are experiencing what appears to be a memory leak without a commensurate increase in Java heap size. Basically the process size continues to grow until the max 32-process size is reached (4Gb) and eventually stops running (no core). Java heap is set to 2Gb min/max. GCs are nominal, so the leak appears to be native and outside Java bytecode.
    We need to determine whether there is a memory leak in BDB, or the IBM JVM or simply a mis-use of BDB in the Java code. What tools/instrumentation/db statistic should be used to help get to root cause? Do you recommend using System Tap (with some particular text command script)? What DB stats should we capture to get to the bottom of this memory leak? What troubleshooting steps can you recommend?
    Thanks ahead of time.
    JE.
    Edited by: 787930 on Aug 12, 2010 5:42 PM

    That's troublesome... DB itself doesn't have stats that track VM in any useful way. I am not familiar with SystemTap but a quick look at it seems to imply that it's better for kernel monitoring than user space. It's pretty hard to get DB to leak significant amounts of memory. The reason is that it mostly uses shared memory carved from the environment. Also if you are neglecting to close or delete some object DB generally complains about it somewhere.
    I don't see how pmap would help if it's a heap leak but maybe I'm missing something.
    One way to rule DB out is to replace its internal memory allocation functions with your own that are instrumented to track how much VM has been allocated (and freed). This is very easy to do using the interfaces:
    db_env_set_func_malloc()
    db_env_set_func_free()
    These are global to your process and your functions will be used where DB would otherwise call malloc() and free(). How you get usage information out of the system is an exercise left to the reader :-) If it turns out DB is the culprit then there is more thinking to do to isolate the problem.
    Other ideas that can provide information if not actual smoking guns:
    -- accelerate reproduction of the problem by allocating nearly all of the VM to the JVM and the DB cache (or otherwise limit the allowable VM in your process)
    -- change the VM allocated to the JVM in various ways
    Regards,
    George

  • Finding Memory Leak in LabVIEW

    Hi NG,
    we wrote a sort of hugh application in labview that collaborates with our
    ..NET driven
    device framework and a variaty of unmanged c++ libs.
    As we are now close to the release we did performance testing and it showed
    up that
    the app is consuming more memory continously.
    We used prefomance counter to check whether the managed objects might not
    get garbage collected
    but this is done OK, since the handle count stays at a constant level.
    We tried to figure out whether one of the c++ libs is causing the problem
    but this is not the case either, since
    the memory leak exists even if the lib functions are just not being called.
    Even labview profiler is not detecting any inconvenient memory consumption
    of any of our vis but
    windows task manager notices a constant memory consumtion of the executable
    (or of labview.exe itselve when running in
    dev. environment).
    Does anybody know what this might be? Has anybody a clue what other tools we
    could use to figure out
    where the problem is?
    Any help is greatly appreciated.
    Thanks in advance, Sebastian Dau!

    "mfitzsimons" <[email protected]> wrote in message
    news:[email protected]..
    > Sebastian,
    > Memory leaks can be VERY hard to find.&nbsp; I use the divide and conquer
    > technique that involves chunking (make into smaller code segments) your
    > code into smaller pieces and running the smaller pieces until you find the
    > memory leak.&nbsp; It can take weeks to find the source.
    you accelerate this process by using the labview profiler.
    > The most common is arrays or any data that increases in size as the
    > program runs.&nbsp; To fix this you can use a FIFO that allows only so
    > many elements to be added before deleting data out of the array.&nbsp; The
    > second source is opening references repeatedly and not closing them.&nbsp;
    > Look closely at any VI that open anything.&nbsp; Do a search for "Memory
    > Leak" on the discussion forum and you will find about 60 postings that may
    > help.&nbsp;
    > Matt
    > If you are using DAQ-MX <a
    > href="http://digital.ni.com/public.nsf/allkb/BAF29EE03747EE4B86256E9700541436?OpenDocument"
    > target="_blank">http://digital.ni.com/public.nsf/allkb/BAF29EE03747EE4B86256E9700541436?OpenDocument</a>
    > &nbsp;
    >
    arrays and refs have already been checked.
    thanks, Sebastian

  • 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

  • 5.0.2 still MEMORY LEAKS with Java on multiple tabs/windows

    same problem with last update.
    Memory Leaks (upto 2.5 GB) when Java applets load
    in multiple windows/tab.
    Someone also have this problem?
    My other post prior of last update:
    http://discussions.apple.com/message.jspa?messageID=12204453#12204453
    Message was edited by: fascox

    If you want to report this issue to Apple's engineering, send a bug report or an enhancement request via its Bug Reporter system. To do this, join the Mac Developer Program—it's free and available for all Mac users and gets you a look at some development software. Since you already have an Apple username/ID, use that. Once a member, go to Apple BugReporter and file your bug report or enhancement request. The nice thing with this procedure is that you get a response and a follow-up number; thus, starting a dialog with engineering.

  • COREDUMP,MEMORY LEAK in java

    HI
    I am frequently hearing these words "CORE DUMP,MEMORY LEAK...."
    Can anybody explain me wat is this?
    Thnx in Advance!

    Check this link for excellent explanation
    http://www.me.umn.edu/~shivane/blogs/cafefeed/2004/06/of-thread-dumps-and-stack-traces.html

Maybe you are looking for

  • HP Officejet Pro 8600 - Faxes from Win 7 computer are cancelled

    When attempting to fax from the computer (i.e. word doc) the fax is cancelled. I have a wireless network, but the computer I am faxing from and the HP 8600 are connected to the router via RJ45 connections. I can fax OK from the HP8600 control panel,

  • About Dot matrix printer device problems

    Hai ,           I have a problems in smartforms and i used the printer device is dot matrix(Used PLY paper)..Its unable to print the vertical & horizontal lines but the corresponding spooler contains correct alignments..in the same time i used HP las

  • Need to DELETE and LOAD data of the Last month to

    Hi Experts, I need to delete the last month data from cube because One material is not updated with a Required value. We have made some changes in Update routine for a Value. The Same change must be reflected from last month of data , So I need to de

  • User Exit for Delivery to add Profit Centre

    Hello All, I need the User Exit to Add the Profit Centre at Delivery level..! I tried in this MV50AFZ1 Form FORM userexit_move_field_to_lips. but its not working... So please let me know the userexit and the code..! Thanks in Advance Regards Babu

  • Restirct OAF page for a user

    Hi All, How can i restrict a page for a user. That is I don't want a particular user to modify the page. So how can i hide a OAF page from the user. When the user logs in the page or responsibility must not be shown. Thanks & Regards, Jeganathan R