How can memory leaks occur?

Hi,
I was just wondering how a memory leak can occur in Java. The garbage collector is supposed to free up all unused variables, so under what circumstances can it happen?

This is not technically a "memory leak". I've seen
this called "loitering objects", which conjures upa
vivid picture: objects hanging around with nothingto
do...I think it's the classic java memory leak. A bug in
a program that prevents the freeing up of memory that
it no longer needs.Yes, but it's not what is traditionally termed a memory leak.
A real memory leak is memory that's claimed by the program but no longer accessible to the program for freeing up.
That can in Java (where what we call a program isn't a complete program but runs inside a virtual machine which handles memory allocation and deallocation) only happen if there's a flaw in the JVM itself which causes errors in memory deallocation (so most likely a flaw in the garbage collector).
In Java the objects you create are always out there somewhere where something can reach them so as to prevent them from being available to the garbage collector.
Different cause, same effect in that in both cases memory isn't getting freed for reuse.

Similar Messages

  • Memory leak occurs in dbc::get

    I found memory leak with using dbc::get in order to retrieve the record.
    I don't know how to free memory after cursor.
    I have expected that "cursor->get(with DB_NEXT flag) allocated memory and cursor->close made memory be free.However, memory was not free when cursor was closed.
    Also, I checked that the memory was free when db was closed ( db->close )
    Could you tell me why this problem occurs and how to deallocate the memory?
    My partial code is below
    =======================================================================================================
    DBC *pTimeCursor;
    // initialize cursor
    m_pDbTime->cursor( m_pDbTime, NULL, &pTimeCursor, 0 );
    DBT key, dataTime, dataData;
    memset(&key, 0, sizeof(key));
    memset(&dataTime, 0, sizeof(dataTime));
    while( pTimeCursor->get(pTimeCursor, &key, &dataTime, DB_NEXT) == 0 )
           recnoNow = *((unsigned long *)key.data);
           timeNow = *((unsigned long *)dataTime.data);
           if( timeNow >= *pTime )
                bFind = true;
                break;
    =======================================================================================================

    Within BDB there are  objects that are created dynamically and reused.   Those objects are released upon db close.     This is normal behavior.
    This sentence meas that it is normal behavior that BDB make allocated memory increasing by using the get function. Is it right?
    I checked that all memory allocated was return upon db close. Unfortunately, I cannot close db in the middle of program because I should access db very often. For this reason, My program do open and close only once.
    Memory keeps increasing, and overflows at last.
    How can I release memory allocated without db close?

  • How can memory be increased in Windows?

    I have a problem with memory. While making many assignments of a certain class I run out of memory (Java.OutOfMemoryException) in Win 98. However with the same program and same amount of assignments I don't run out of memory in Win NT. Is there differences how they handle memory? Can memory be extended in Win 98?

    i dont know about the differences between windows98 and nt, but you could increase memory for the vm with this settings at the command line:
    -Xmsn
    Specify the initial size, in bytes, of the memory allocation pool.
    This value must be a multiple of 1024 greater than 1MB. Append the letter k or K to indicate kilobytes, or m or M to indicate megabytes. The default value is 2MB.
    Examples:
    -Xms6291456
    -Xms6144k
    -Xms6m
    -Xmxn
    Specify the maximum size, in bytes, of the memory allocation pool.
    This value must a multiple of 1024 greater than 2MB. Append the letter
    k or K to indicate kilobytes, or m or
    M to indicate megabytes. The default value is 64MB. Examples:
    -Xmx83886080
    -Xmx81920k
    -Xmx80m
    if you have the docs look here:
    jdk1.3/docs/tooldocs/win32/java.html
    carsten

  • DataSocket memory leak problem (2VO0SF00) -- more info?

    When upgrading to LabVIEW 8.5 recently, I noticed the following known issue in the readme file:
    "ID: 2VO0SF00
    DataSocket/OPC Leaks Memory using ActiveX VIs to perform open-write-close repeatedly
    If you call the DataSocket Open, DataSocket Write, and DataSocket Close functions in succession repeatedly, LabVIEW leaks memory. Workaround — To correct this problem, call the DataSocket Open function once, use the DataSocket Write function to write multiple times, and then use the DataSocket Close function."
    Looking back, I think this problem may have been present in previous LabVIEW releases as well, and might be giving rise to a problem that's been dogging me for quite some time (see my thread, "Error 66 with DataSockets", http://forums.ni.com/ni/board/message?board.id=170&thread.id=187206), in addition to general slow/glitchy behaviour when my VI's have been running continuously for a long time. But in order to determine whether or not this issue affects me, and how I should go about fixing it in the context of my own programs, I need a bit more information about the nature of the issue itself and the inner workings of the DataSocket VI's. Any help or insight the community can provide into this would be greatly appreciated!
    Here are my questions:
    It is my understanding from the "known issue" description above that the memory leak happens when you have a DS Open wired to a DS Write wired to a DS Close, all inside a loop (example 1), and that the suggested workaround would be to move the DS Open and DS Close functions out of the loop on opposite sides, wired to the DS Write which remains inside the loop (example 2). Is this correct?
    Does this leak also happen when performing DS open-read-close's repeatedly (example 3)?
    What happens when a DS Write (or DS Read) is called without a corresponding DS Open and DS Close (examples 4a and 4b)? Does it implicitly do a DS open before doing the write operation and a DS close afterwards? What I'm getting at is this: would having an isolated DS Write (or DS Read) inside a loop, not connected to any DS Open or DS Close functions at all, cause this same memory leak?
    If one computer is running the DS server and a second computer is running the VI with the repeated open-write-close's, on which computer does the memory leak occur?
    In my question #1 workaround (example 2), the DS Open and DS Close outside the loop are routed through a shift register and in to and out of the DS Write inside the loop. If the DS connection id goes into the DS Write "connection in" and then splits and goes around the DS Write and out to the DS Close, without coming out of the DS Write "connection out" (example 5), will the memory leak still be avoided? I.e. if the DS Write function doesn't have anything connected to its "connection out", will it try to do an implicit DS Close?
    If the VI causing the memory leak is stopped, but LabVIEW stays running, will the leaked memory be reclaimed? What if the VI is closed? What if all of LabVIEW is closed?
    FYI, in the examples above "x1a" is a statically-defined DataSocket on the DS server running on the computer Max, to which the computer running the example VI's has read/write access. My actual application has numerous VI's and hundreds of DataSocket items, many of which are written to / read from every 50-100 ms in the style of examples 4a and 4b.
    Does anyone have any idea about this stuff?
    Thanks in advance,
    Patrick
    Attachments:
    examples_jpg1.zip ‏63 KB
    examples_vi1.zip ‏40 KB

    Hi Meghan,
    Yes, some of the larger VIs in my application do write to / read from several hundred DataSockets, so it's not feasible to use shift registers for each one individually, and hence why I'm passing the references into an array, etc.
    Your Alternate Solution 2 is more along the lines of something that would work for me. However, my actual code has a lot of nested loops, sequences and DataSocket items which are not all written to in the same frame, so this solution would still be difficult to implement: it would be cumbersome to unpack the entire 500-element reference id array and build a new one (maintaining the positions and values of the unaffected elements) every time I write to some small subset of the DataSockets.
    I think I have a solution which solves the problem and is also scalable to the size of my application -- I've attached it as Example 7. Do you think this will avoid the memory leak? It's the same as your Alternate Solution 2, except that instead of building a new array out of the DS Write reference outs, each reference out replaces the appropriate element of the original array.
    If I understand you correctly, in order to avoid implicit reference opens and closes, a DS Write needs to have both it's reference in and reference out wired to something. Thus, even though my Example 7 replaces an element of the array with an identical value, and therefore doesn't actually change the array (which would be a silly thing to do normally), the DS Writes have their reference outs wired to something, and eventually in a convoluted way to a DS Close, so it should avoid the memory leak.
    Just out of curiosity (I don't think anything like this would apply to my application or any fixes I implement), when would the implicit reference close happen in the attached Example 8? The DS Write has its reference in and reference out both connected to temporally "adjacent" DS Writes via the shift register, so perhaps it wouldn't try to close the reference on each loop iteration? Or would it look into the future and see that there is no DS Close and decide to implicitly do that itself? Or maybe only the DS Write on the last loop iteration does this?
    Thanks for bearing with me through this,
    Patrick
    Attachments:
    example73.JPG ‏40 KB
    example83.JPG ‏14 KB

  • Memory leak in ODBC Driver version 8.1.7.8?

    We have a web application connected to an 8.1.7 database on a MS Windows 2000 SP 2 server.
    We recently upgraded ODBC driver from 8.1.7.7 to 8.1.7.8 and found that we ran out of virtual memory.
    On further investigations, a simple refresh of our summary web page (going to the database to select a small recordset - even when there are only 2 records with 6 small VARCHAR2 fields) causes the virtual memory usage to increase by approximately 1Mb each refresh.
    The same refresh using driver 8.1.7.7 occasionally increases the VM usage by 4Kb!
    Is there a memory leak in ODBC driver version 8.1.7.8?

    Hello Thomas,
    thanks for your tips, but they did not help. Activating Connection Polling did not change anything. And opening another connection did not help, either. I did it the following way:
    Sub memtest2()
    Dim conODBC As New ADODB.Connection
    conODBC.ConnectionString = "Data Source='xxxx';User ID='xxx';Password='xxx'"
    conODBC.Open
    Dim Rs1 As Recordset, Rs2 As Recordset, DB1 As Database
    Set DB1 = CurrentDb
    Set Rs1 = DB1.OpenRecordset("select id from artikel")
    Do While Not Rs1.EOF
        Set Rs2 = DB1.OpenRecordset("select * from artikel where id=" & Rs1("id"))
        'do something
        Rs2.Close
        Set Rs2 = Nothing
        Rs1.MoveNext
    Loop
    Rs1.Close
    Set Rs1 = Nothing
    DB1.Close
    Set DB1 = Nothing
    conODBC.Close
    End Sub
    Perhaps one of you has another tip how this can be done.
    @Lukasz:
    using a seperate ADODB.Connection works fine, but that does not solve the problem itself. At first I would have to rewrite much code and the second much bigger thing is that the memory leak occurs even when working with bound forms in MS Access. For example: I have one large form with many subforms on it. If i go from record to record on this form the memory usage is increasing dramatically fast and there is no way to influence what kind of connection MS Access is using for bound forms.
    Regards
    Thorstem

  • Memory leak in Oracle Text under Oracle 8.1.7!!!

    When I wanted to use USER_DATASOTRE preference to use my own formatting tag in Oracle Text, the memory leak occured in Oracle Text!
    Memory just freed when I close SQL*Plus program
    My formatting procedure is so easy
    PROCEDURE format_tag(r IN ROWID, tlob IN OUT NOCOPY CLOB) IS
    BEGIN
    SELECT '<C>' &#0124; &#0124; catalog_id &#0124; &#0124; '</C></T>' &#0124; &#0124; tag_id &#0124; &#0124; '</T><V>' &#0124; &#0124; tag_value &#0124; &#0124; '</V>' INTO buf
    FROM tbl_catalog WHERE ROWID=r;
    dbms_lob.trim(tlob, 0); -- set LOB's size to zero
    dbms_lob.write(tlob, length(buf), 1, buf);
    END;
    The typical rows are about 100,000 ( The actual records are tens of millions )
    How can I solve this problem?

    Thanks for your reply
    I'm using Oracle 8.1.7.0.0 on Windows 2000
    The preferences are as follows:
    DECLARE
    ds VARCHAR2(30):= 'dts_catalog';
    grp VARCHAR2(30):= 'grp_catalog';
    lxr VARCHAR2(30):= 'lxr_catalog';
    wrd VARCHAR2(30):= 'wrd_catalog';
    BEGIN
    ctx_ddl.create_preference(wrd, 'BASIC_WORDLIST');
    ctx_ddl.set_attribute(wrd, 'STEMMER', 'NULL');
    ctx_ddl.create_preference(lxr, 'BASIC_LEXER');
    ctx_ddl.set_attribute(lxr, 'INDEX_TEXT', 'TRUE');
    ctx_ddl.set_attribute(lxr, 'INDEX_THEMES', 'FALSE');
    ctx_ddl.create_preference(ds, 'USER_DATASTORE');
    ctx_ddl.set_attribute(ds, 'OUTPUT_TYPE', 'VARCHAR2');
    ctx_ddl.set_attribute(ds, 'PROCEDURE', 'pkg_catalog.format');
    ctx_ddl.create_section_group(grp, 'BASIC_SECTION_GROUP');
    ctx_ddl.add_field_section(grp, 'catalog', 'C', TRUE);
    ctx_ddl.add_field_section(grp, 'tag', 'T', TRUE);
    TRUE);
    ctx_ddl.add_field_section(grp, 'value', 'V', TRUE);
    END;
    the STORAGE preferences are not here ( because they are long )
    Index statement that I used for indexing
    CREATE INDEX idx_catalog_info ON tbl_catalog_info(val)
    INDEXTYPE IS ctxsys.context
    PARAMETERS(
    'STORAGE stg_catalog
    DATASTORE dts_catalog
    SECTION GROUP grp_catalog
    LEXER lxr_catalog
    WORDLIST wrd_catalog
    MEMORY 24M'
    I changed my last version of procedure and using VARCHAR2 parameter type instead of CLOB, but memory leak persist during building index.
    so I used a simple trick by writing a package and counting the records to be indexed, after each 100,000 records I used DBMS_SESSION.FREE_UNUSED_USER_MEMORY procedure to free unused session's memory.
    the package is as follows:
    CREATE OR REPLACE PACKAGE pkg_catalog IS
    PROCEDURE format(r ROWID, buf IN OUT NOCOPY VARCHAR2);
    END pkg_catalog;
    CREATE OR REPLACE PACKAGE BODY pkg_catalog IS
    recs PLS_INTEGER:= 0;
    PROCEDURE format(r ROWID, buf IN OUT NOCOPY VARCHAR2) IS
    BEGIN
    SELECT '<C>'&#0124; &#0124;catalog_id&#0124; &#0124;'</C><T>'&#0124; &#0124;tag_id&#0124; &#0124;subfield_id&#0124; &#0124;'</T><V>'&#0124; &#0124;val&#0124; &#0124;'</V>' INTO buf FROM &usr.tbl_catalog_info WHERE ROWID=r;
    recs:= recs + 1;
    IF recs>100000 THEN
    recs:= 0;
    dbms_session.free_unused_user_memory; -- clean-out memory garbage
    END IF;
    END format;
    END pkg_catalog;
    My problem solved, but it is very marvelous "Why Oracle does not free unused session's memory?"

  • Memory leak in ODBC driver

    I have a serious problem with the maxdb ODBC Driver. I tested Version 7.06.03.00 and some older Versions.
    Here is a little example for MS Access to show the problem. The table "artikel" is a linked maxdb table. The example code opens and closes a recordset in a loop. You can see the memory usage in the task manger going up and up. If you have many recordsets in the table, the system is crashing when it is going out of memory.
    If i change the linked table to for example a mysql-table the memory usage is stable. So I think there must be a memory leak in the maxdb odbc driver.
    Example code:
    Sub memtest()
    Dim RS1 As Recordset, RS2 As Recordset, DB1 As Database
    Set DB1 = CurrentDb
    Set RS1 = DB1.OpenRecordset("select id from artikel")
    Do While Not RS1.EOF
        Set RS2 = DB1.OpenRecordset("select * from artikel where id=" & RS1("id"))
        'do something
        RS2.Close
        Set RS2 = Nothing
        RS1.MoveNext
    Loop
    RS1.Close
    Set RS1 = Nothing
    DB1.Close
    Set DB1 = Nothing
    End Sub
    I hope you can follow me and find the leak.
    Thorsten

    Hello Thomas,
    thanks for your tips, but they did not help. Activating Connection Polling did not change anything. And opening another connection did not help, either. I did it the following way:
    Sub memtest2()
    Dim conODBC As New ADODB.Connection
    conODBC.ConnectionString = "Data Source='xxxx';User ID='xxx';Password='xxx'"
    conODBC.Open
    Dim Rs1 As Recordset, Rs2 As Recordset, DB1 As Database
    Set DB1 = CurrentDb
    Set Rs1 = DB1.OpenRecordset("select id from artikel")
    Do While Not Rs1.EOF
        Set Rs2 = DB1.OpenRecordset("select * from artikel where id=" & Rs1("id"))
        'do something
        Rs2.Close
        Set Rs2 = Nothing
        Rs1.MoveNext
    Loop
    Rs1.Close
    Set Rs1 = Nothing
    DB1.Close
    Set DB1 = Nothing
    conODBC.Close
    End Sub
    Perhaps one of you has another tip how this can be done.
    @Lukasz:
    using a seperate ADODB.Connection works fine, but that does not solve the problem itself. At first I would have to rewrite much code and the second much bigger thing is that the memory leak occurs even when working with bound forms in MS Access. For example: I have one large form with many subforms on it. If i go from record to record on this form the memory usage is increasing dramatically fast and there is no way to influence what kind of connection MS Access is using for bound forms.
    Regards
    Thorstem

  • Memory Leak with JDialog in Java 1.4.2_07

    Hello!
    All books I have read say to close a JDialog, it is enough to call the Method "dispose". Now I have written my first applikation an with every Dialog I open, the Software needs more RAM. With every Dialog I open, my software needs 1,5 MB RAM.
    I can`t reuse the Dialogs, because the user needs to look at view at the same time
    The Question is, how to close a JDialog correct that the GC can clean all Objects in RAM.
    Here are my Example Programm where you can view the differences. I tryed a view things out. With every Dialog the software needs xxx kb of RAM (its only a little example).
    Look at the Task Manager to look the real RAM needage.
    Thanks for Help
    Rainer
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    public class TestRAMUsage extends JFrame {
         private JPanel jContentPane = null;
         private JMenuBar jJMenuBar = null;
         private JMenu fileMenu = null;
         private JMenuItem exitMenuItem = null;
         private JButton jB_showandclose_normal = null;
         private JButton jB_showandclose_advanced = null;
          * This method initializes jB_showandclose_normal     
          * @return javax.swing.JButton     
         private JButton getJB_showandclose_normal() {
              if (jB_showandclose_normal == null) {
                   jB_showandclose_normal = new JButton();
                   jB_showandclose_normal.setBounds(new java.awt.Rectangle(43,30,214,18));
                   jB_showandclose_normal.setText("open/close Dialog normal x 50");
                   jB_showandclose_normal.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent e) {
                             for (int i = 0; i < 50; i++) {
                                  TestDialog td = new TestDialog();
                                  td.show();
                                  td.close_normal();
                             System.gc();
              return jB_showandclose_normal;
          * This method initializes jB_showandclose_advanced     
          * @return javax.swing.JButton     
         private JButton getJB_showandclose_advanced() {
              if (jB_showandclose_advanced == null) {
                   jB_showandclose_advanced = new JButton();
                   jB_showandclose_advanced.setBounds(new java.awt.Rectangle(16,76,260,18));
                   jB_showandclose_advanced.setText("open/close Dialog advanced x 50");
                   jB_showandclose_advanced.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent e) {
                             for (int i = 0; i < 50; i++) {
                                  TestDialog td = new TestDialog();
                                  td.show();
                                  td.close_advanced();
                             System.gc();
              return jB_showandclose_advanced;
          * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              TestRAMUsage application = new TestRAMUsage();
              application.show();
          * This is the default constructor
         public TestRAMUsage() {
              super();
              initialize();
          * This method initializes this
          * @return void
         private void initialize() {
              this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              this.setJMenuBar(getJJMenuBar());
              this.setSize(300, 200);
              this.setContentPane(getJContentPane());
              this.setTitle("Application");
          * This method initializes jContentPane
          * @return javax.swing.JPanel
         private JPanel getJContentPane() {
              if (jContentPane == null) {
                   jContentPane = new JPanel();
                   jContentPane.setLayout(null);
                   jContentPane.add(getJB_showandclose_normal(), null);
                   jContentPane.add(getJB_showandclose_advanced(), null);
              return jContentPane;
          * This method initializes jJMenuBar     
          * @return javax.swing.JMenuBar     
         private JMenuBar getJJMenuBar() {
              if (jJMenuBar == null) {
                   jJMenuBar = new JMenuBar();
                   jJMenuBar.add(getFileMenu());
              return jJMenuBar;
          * This method initializes jMenu     
          * @return javax.swing.JMenu     
         private JMenu getFileMenu() {
              if (fileMenu == null) {
                   fileMenu = new JMenu();
                   fileMenu.setText("File");
                   fileMenu.add(getExitMenuItem());
              return fileMenu;
          * This method initializes jMenuItem     
          * @return javax.swing.JMenuItem     
         private JMenuItem getExitMenuItem() {
              if (exitMenuItem == null) {
                   exitMenuItem = new JMenuItem();
                   exitMenuItem.setText("Exit");
                   exitMenuItem.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                             System.exit(0);
              return exitMenuItem;
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    public class TestDialog extends JDialog {
         private static final long serialVersionUID = -4326706771573368209L;
         private JPanel jContentPane = null;
         private JButton jB_drucken = null;
         private JTextField jTF_hallo = null;
         private JButton jB_close = null;
          * This is the default constructor
         public TestDialog() {
              super();
              initialize();
          * This method initializes this
          * @return void
         private void initialize() {
              this.setSize(541, 255);
              this.setTitle("Speicher Dialog");
              this.setContentPane(getJContentPane());
          * This method initializes jContentPane
          * @return javax.swing.JPanel
         private JPanel getJContentPane() {
              if (jContentPane == null) {
                   jContentPane = new JPanel();
                   jContentPane.setLayout(null);
                   jContentPane.add(getJB_drucken(), null);
                   jContentPane.add(getJTF_hallo(), null);
                   jContentPane.add(getJB_close(), null);
              return jContentPane;
          * This method initializes jB_drucken
          * @return javax.swing.JButton
         private JButton getJB_drucken() {
              if (jB_drucken == null) {
                   jB_drucken = new JButton();
                   jB_drucken.setBounds(new java.awt.Rectangle(45, 88, 211, 19));
                   jB_drucken.setText("Sag Hallo Welt");
              return jB_drucken;
          * This method initializes jTF_hallo
          * @return javax.swing.JTextField
         private JTextField getJTF_hallo() {
              if (jTF_hallo == null) {
                   jTF_hallo = new JTextField();
                   jTF_hallo.setBounds(new java.awt.Rectangle(269, 88, 228, 19));
              return jTF_hallo;
          * This method initializes jB_close
          * @return javax.swing.JButton
         private JButton getJB_close() {
              if (jB_close == null) {
                   jB_close = new JButton();
                   jB_close.setBounds(new java.awt.Rectangle(196, 179, 109, 22));
                   jB_close.setText("Schlie�en");
                   jB_close.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent e) {
                             try {
                                  // setVisible(false);
                                  dispose();
                                  removeAll();
                                  // getContentPane().removeAll();
                                  // finalize();
                             } catch (Throwable e1) {
                                  // TODO Auto-generated catch block
                                  e1.printStackTrace();
              return jB_close;
          * Dispose the Dialog
         public void close_normal() {
              dispose();
          * Set all Variables to null
          * Remove all Container
          * dispose the Dialog
          * and finalize it!
         public void close_advanced() {
              // System.out.println(this.);
              dispose();
              // show();
              jContentPane = null;
              jB_drucken = null;
              jTF_hallo = null;
              jB_close = null;
              getContentPane().removeAll();
              removeAll();
              try {
                   finalize();
              } catch (Throwable e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
    } // @jve:decl-index=0:visual-constraint="10,10"

    I have use Methods in some Software Produkts. But if your Software
    use 30 MB in RAM the Runtime classes say 12 MB used. I don`t think
    that this works hereThe 12 MB is the memory used of the available 30 MB memory available. Once the VM get its memory from the OS, it does not have to return the memory back to the OS right away.
    By calling System.gc() does nt guarentee the garbage collector to be activated right away. you are just asking the garbage collector to run when it get a chance. Since the emeory is not near the max memory available...the gc is likely not going to run. Futhermore, if your application is running..the gc is likely wont run, unless memory is needed when you reach the max limit.
    because the user want to view at more than one Dialog at the same
    timeunderstandable..i just hope the 50 dialogs is just for testing the memory. i can't imagine any user would want to open 50 dialog at the same time =)
    And the other is, that the Variables in the Dialog class wouldn`t clean
    in RAM (that was the reason to set all to null!)why would it not be? When you dispose the dialog, the object will be null out..so when the garbage collector kick in, it will reclaim the memory. Now, if you have references to object in the dialog, that reference will be null out as well..the object may still exist (by having another live object having a reference to it)...the garbage collector would reclaim the dialog memory..but not the "live" object that the dialog has reference to.
    I ran the application..testing both button.
    The top button..there were little memory consumption..the second button consume a little memory bit-by-bit. I see no memory leak here. What happens is you called GC() 50 times..but it will only run one time when it get a chance...by nulling out the variables, and calling finalize()..it actually slow down the garbage collecting...that's why you should not even obther with having those two method. Furthermore, finalize method may not even be called.
    Memory leak occurs when you have a reference from an object still hanging around, but that object is no longer needed. This is a design issue.
    example
    public class A{
        Item item = new Item();
        public void getItem(){ return item; };
    public class B{
        Item item;
        public B(A a){
            item = a.getItem();
    A a = new A();
    B b = new B(a);
    a = null;when a is null out..the item reference is null, but the actual object still exist and 'b' has a reference to it. so by nulling out those object does not mean you just got rid of the object. it's better to let the object scope run out..and the garbage collector to collect it.. When you null out the object, you could accidentally null out an object that some other object may be using.

  • Potential Memory Leak during Marshelling of a Web Service Response

    I believe I have found a memory leak when using the configuration below.
    The memory leak occurs when calling a web service. When the web service function is marshelling the response of the function call, an "500 Internal Server Error ... java.lang.OutOfMemoryError" is returned from OC4J. This error may be seen via the TCP Packet Monitor in JDeveloper.
    Unfortunately no exception dump is outputted to the OC4J log.
    Configuration:
    Windows 2000 with 1 gig ram
    JDeveloper 9.0.5.2 with JAX/RPC extension installed
    OC4J 10.0.3
    Sun JVM version 1.4.2_03-b02
    To demonstrate the error I created a simple web service and client. See below the client and web service function that demonstrates it.
    The web service is made up of a single function called "queryTestOutput".
    It returns an object of class "TestOutputQueryResult" which contains an int and an array.
    The function call accepts a one int input parameter which is used to vary the size of array in the returned object.
    For small int (less than 100). Web service function returns successfully.
    For larger int and depending on the size of memory configuration when OC4J is launched,
    the OutOfMemoryError is returned.
    The package "ws_issue.service" contains the web service.
    I used the Generate JAX-RPC proxy to build the client (found in package "ws_issue.client"). Package "types" was
    also created by Generate JAX-RPC proxy.
    To test the web service call execute the class runClient. Vary the int "atestValue" until error is returned.
    I have tried this with all three encodings: RPC/Encoded, RPC/Literal, Document/Literal. They have the
    same issue.
    The OutOfMemory Error is raised fairly consistently using the java settings -Xms386m -Xmx386m for OC4J when 750 is specified for the input parameter.
    I also noticed that when 600 is specified, the client seems to hang. According to the TCP Packet Monitor,
    the response is returned. But, the client seems unable to unmarshal the message.
    ** file runClient.java
    // -- this client is using Document/Literal
    package ws_issue.client;
    public class runClient
    public runClient()
    * @param args
    * Test out the web service
    * Play with the atestValue variable to until exception
    public static void main(String[] args)
    //runClient runClient = new runClient();
    long startTime;
    int atestValue = 1;
    atestValue = 2;
    //atestValue = 105; // last one to work with default memory settings in oc4j
    //atestValue = 106; // out of memory error as seen in TCP Packet Monitor
    // fails with default memory settings in oc4j
    //atestValue = 600; // hangs client (TCP Packet Monitor shows response)
    // when oc4j memory sessions are -Xms386m -Xmx386m
    atestValue = 750; // out of memory error as seen in TCP Packet Monitor
    // when oc4j memory sessions are -Xms386m -Xmx386m
    try
    startTime = System.currentTimeMillis();
    Ws_issueInterface ws = (Ws_issueInterface) (new Ws_issue_Impl().getWs_issueInterfacePort());
    System.out.println("Time to obtain port: " + (System.currentTimeMillis() - startTime) );
    // call the web service function
    startTime = System.currentTimeMillis();
    types.QueryTestOutputResponse qr = ws.queryTestOutput(new types.QueryTestOutput(atestValue));
    System.out.println("Time to call queryTestOutput: " + (System.currentTimeMillis() - startTime) );
    startTime = System.currentTimeMillis();
    types.TestOutputQueryResult r = qr.getResult();
    System.out.println("Time to call getresult: " + (System.currentTimeMillis() - startTime) );
    System.out.println("records returned: " + r.getRecordsReturned());
    for (int i = 0; i<atestValue; i++)
    types.TestOutput t = r.getTestOutputResults();
    System.out.println(t.getTestGroup() + ", " + t.getUnitNumber());
    catch (Exception e)
    e.printStackTrace();
    ** file wsmain.java
    package ws_issue.service;
    import java.rmi.RemoteException;
    import javax.xml.rpc.ServiceException;
    import javax.xml.rpc.server.ServiceLifecycle;
    public class wsmain implements ServiceLifecycle, ws_issueInterface
    public wsmain()
    public void init (Object p0) throws ServiceException
    public void destroy ()
    System.out.println("inside ws destroy");
    * create an element of the array with some hardcoded values
    private TestOutput createTestOutput(int cnt)
    TestOutput t = new TestOutput();
    t.setComments("here are some comments");
    t.setConfigRevisionNo("1");
    t.setItemNumber("123123123");
    t.setItemRevision("arev" + cnt);
    t.setTestGroup(cnt);
    t.setTestedItemNumber("123123123");
    t.setTestedItemRevision("arev" + cnt);
    t.setTestResult("testResult");
    t.setSoftwareVersion("version");
    t.setTestConditions("conditions");
    t.setStageName("world's a stage");
    t.setTestMode("Test");
    t.setTestName("test name");
    t.setUnitNumber("UnitNumber"+cnt);
    return t;
    * Web service function that is called
    * Create recCnt number of "records" to be returned
    public TestOutputQueryResult queryTestOutput (int recCnt) throws java.rmi.RemoteException
    System.out.println("Inside web service function queryTestOutput");
    TestOutputQueryResult r = new TestOutputQueryResult();
    TestOutput TOArray[] = new TestOutput[recCnt];
    for (int i = 0; i< recCnt; i++)
    TOArray[i] = createTestOutput(i);
    r.setRecordsReturned(recCnt);
    r.setTestOutputResults(TOArray);
    System.out.println("End of web service function call");
    return r;
    * @param args
    public static void main(String[] args)
    wsmain wsmain = new wsmain();
    int aval = 5;
    try
    TestOutputQueryResult r = wsmain.queryTestOutput(aval);
    for (int i = 0; i<aval; i++)
    TestOutput t = r.getTestOutputResults()[i];
    System.out.println(t.getTestGroup() + ", " + t.getUnitNumber());
    catch (Exception e)
    e.printStackTrace();
    ** file ws_issueInterface.java
    package ws_issue.service;
    import java.rmi.Remote;
    import java.rmi.RemoteException;
    public interface ws_issueInterface extends java.rmi.Remote
    public TestOutputQueryResult queryTestOutput (int recCnt) throws java.rmi.RemoteException;
    ** file TestOutputQueryResult.java
    package ws_issue.service;
    public class TestOutputQueryResult
    private long recordsReturned;
    private TestOutput[] testOutputResults;
    public TestOutputQueryResult()
    public long getRecordsReturned()
    return recordsReturned;
    public void setRecordsReturned(long recordsReturned)
    this.recordsReturned = recordsReturned;
    public TestOutput[] getTestOutputResults()
    return testOutputResults;
    public void setTestOutputResults(TestOutput[] testOutputResults)
    this.testOutputResults = testOutputResults;
    ** file TestOutput.java
    package ws_issue.service;
    public class TestOutput
    private String itemNumber;
    private String itemRevision;
    private String configRevisionNo;
    private String testName;
    private String testConditions;
    private String stageName;
    private String testedItemNumber;
    private String testedItemRevision;
    private String unitNumber;
    private String testStation;
    private String testResult;
    private String softwareVersion;
    private String operatorID;
    private String testDate; // to be datetime
    private String comments;
    private int testGroup;
    private String testMode;
    public TestOutput()
    public String getComments()
    return comments;
    public void setComments(String comments)
    this.comments = comments;
    public String getConfigRevisionNo()
    return configRevisionNo;
    public void setConfigRevisionNo(String configRevisionNo)
    this.configRevisionNo = configRevisionNo;
    public String getItemNumber()
    return itemNumber;
    public void setItemNumber(String itemNumber)
    this.itemNumber = itemNumber;
    public String getItemRevision()
    return itemRevision;
    public void setItemRevision(String itemRevision)
    this.itemRevision = itemRevision;
    public String getOperatorID()
    return operatorID;
    public void setOperatorID(String operatorID)
    this.operatorID = operatorID;
    public String getSoftwareVersion()
    return softwareVersion;
    public void setSoftwareVersion(String softwareVersion)
    this.softwareVersion = softwareVersion;
    public String getStageName()
    return stageName;
    public void setStageName(String stageName)
    this.stageName = stageName;
    public String getTestConditions()
    return testConditions;
    public void setTestConditions(String testConditions)
    this.testConditions = testConditions;
    public String getTestDate()
    return testDate;
    public void setTestDate(String testDate)
    this.testDate = testDate;
    public String getTestName()
    return testName;
    public void setTestName(String testName)
    this.testName = testName;
    public String getTestResult()
    return testResult;
    public void setTestResult(String testResult)
    this.testResult = testResult;
    public String getTestStation()
    return testStation;
    public void setTestStation(String testStation)
    this.testStation = testStation;
    public String getTestedItemNumber()
    return testedItemNumber;
    public void setTestedItemNumber(String testedItemNumber)
    this.testedItemNumber = testedItemNumber;
    public String getTestedItemRevision()
    return testedItemRevision;
    public void setTestedItemRevision(String testedItemRevision)
    this.testedItemRevision = testedItemRevision;
    public String getUnitNumber()
    return unitNumber;
    public void setUnitNumber(String unitNumber)
    this.unitNumber = unitNumber;
    public int getTestGroup()
    return testGroup;
    public void setTestGroup(int testGroup)
    this.testGroup = testGroup;
    public String getTestMode()
    return testMode;
    public void setTestMode(String testMode)
    this.testMode = testMode;

    I use web services a lot and I sympathize with your issue. I
    struggle with similar issues and I found this great utility that
    will help you confirm if your webservice is returning the data
    correctly to Flex. I know you said it works in other applications
    but who knows if flex is calling it correctly etc. This utility is
    been the most amazing tool in helping me resolve web service
    issues.
    http://www.charlesproxy.com/
    Once you can confirm the data being returned is good you can
    try several things in flex. Try changing your result format to
    object or e4x etc. See how that plays out. Not sure where your
    tapping in to look at your debugger, you might want to catch it
    right at the result handler before converting to any collections. .
    If nothing here helps maybe post some code to look at. .
    .

  • Memory leak when transferring pdf...help needed

    Dear All,
    I'm a newbie in developing java app. I'm making a web based application in reporting using JSP. java 1.6.02, jasper report 204, i-report 2.0.0
    Client : OS : Win xp, memory 512MB
    Server : Tomcat 6.0
    DB Server : SQL Server 2005
    OS Server : Windows Server 2003, memory 1GB
    Report spec : .pdf based, with up to 1million record
    Here's the code :
    String query;
            try {
            String filereport = request.getRealPath("division/accounting/template/POReport.jrxml");
            InputStream input = new FileInputStream(filereport);
            Class.forName(odbcDriver);
            Connection conn = DriverManager.getConnection(odbcURL,username,passwd);
            ResultSet rset = null;
            CallableStatement cs = null;
            query = "{ call sp_tpo_list }";
              cs = conn.prepareCall(query);
              rset = cs.executeQuery();
            JRDataSource dataSource = new JRResultSetDataSource(rset);
            JasperDesign design = JRXmlLoader.load(input);
            JasperReport report = JasperCompileManager.compileReport(design);
            JasperPrint print = JasperFillManager.fillReport(report, null, dataSource);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            JasperExportManager.exportReportToPdfStream(print, baos);
            response.setContentType("application/pdf");
            response.setContentLength(baos.size());
            ServletOutputStream sos;
            sos = response.getOutputStream();
            baos.writeTo(sos);
            sos.flush();
            rset.close();
            cs.close();
            conn.close();
            sos.close();
            baos.close();
            input.close();      
            catch (FileNotFoundException fe) {}
            catch (JRException jre) {}
            catch (ClassNotFoundException cnfe) {}
            catch (SQLException sqle) {} 
            catch (IOException ioe) {}I've already increase heap memory in Tomcat Manager -Xms 64Mb -Xmx 512Mb.
    But when i test with 1million record, out of heap memory error is coming out.
    When i test with 500.000 record, it work out, but only when 1 client access. More than 1 client, out of heap memory error generated by the system.
    How can this happen? How can i detect memory leaks occured in the program?
    And pls let me know if you see something is missing in the code above.
    Thank you

    I dont think you have a memory leak. I think the problem is the xml file is 1000000 records long and takes up too much memory. Even if you find a way to increase memory size, you are loading down the server too much for other people's applications to run. I suggest instead reading up on xml and learning how to read in only a few records at a time, processing it, and getting the next set of records to process. There are two methods to parse an xml file using an xml parser, one is to parse it all and put it in memory, the other is to process one record at a time (an xml book explains it better).
    However, I question why you have reports that are 1000000 records long. end-users cannot effectively use such records (you cant scroll through 1000000 records). I suggest finding a way to greatly decrease the number of records in each file such as by providing just the records a particular user needs to do his job and not all records. For instance, put a textfield on his screen to let him only fetch records within a certain date range.
    Lastly, I suggest putting your code in a try/catch/finally block where the finally block actually closes the objects. Example:
    finally{
    if(conn!=null)
    conn.close();
    }

  • Memory leak within FOProcessor class

    Hi all,
    I'm trying to use the XML Publisher API (5.6.2 and 5.6.3) to generate PDF documents from XSL templates and XML data in a J2EE environment (Jboss 4.0.5) with Struts but a memory leak occurs.
    It seems not to be a multithreading issue because the leak is there even if the PDF documents are generated one by one.
    I made many tests to isolate the leak and I have simplified my code as much as possible: it seems to happen within the FOProcessor class.
    One of the tests generates 4,500 PDF documents (one at a time) from an XML file (3 KB) and an XSL file (74 KB with blanks). Nothing else is done with the Jboss server during this test. The XSL file was created before the test from a RTF file with XML Publisher. The memory leak is around 70 KB for each PDF document (around 300 MB for the whole test).
    As you can see below from the heap histogram (taken at end of test after a full garbage collection) it seems that the XSL and XML elements/attributes are not released (and thus never garbage collected).
    Did I miss something or is there an actual problem with the XML/XSL parsing within the XML Publisher API?
    Thanks for your help.

    Object Histogram:
    Size    Count     Class description
    131376968 2353450 java.lang.Object[]
    60389464 937300  char[]
    48260304 335141  oracle.xml.parser.v2.XSLResultElement
    35690000 2230625 oracle.xml.util.FastVector
    24127104 1005296 java.lang.String
    16539120 413478  oracle.xml.parser.v2.XSLNode$AttrValueTmpl
    14757064 128058  int[]
    13348768 417149  java.lang.ref.Finalizer
    12701776 102220  * ConstMethodKlass
    12544808 23433   byte[]
    12204080 108965  oracle.xml.parser.v2.XSLText
    8344600 86584   java.util.Hashtable$Entry[]
    7363768 102220  * MethodKlass
    5592784 138700  * SymbolKlass
    5362256 335141  oracle.xml.parser.v2.XSLAttributeSet[]
    5267336 8135    * ConstantPoolKlass
    5234016 163563  java.util.TreeMap$Entry
    5121744 213406  java.util.Hashtable$Entry
    4900480 61256   oracle.xml.parser.v2.XPathStep
    4087120 51089   java.lang.reflect.Method
    3823216 40276   java.util.HashMap$Entry[]
    3524696 8135    * InstanceKlassKlass
    3378000 84450   java.util.Hashtable
    3064872 127703  java.util.HashMap$Entry
    2971904 6880    * ConstantPoolCacheKlass
    2968560 26505   oracle.xml.parser.v2.XSLValueOf
    2770656 24738   oracle.xml.parser.v2.XSLVariable
    2167520 27094   oracle.xml.parser.v2.XPathFunctionCall
    1880088 33573   oracle.xml.parser.v2.PathExpr
    1726360 61482   java.lang.String[]
    1573720 39343   java.util.HashMap
    1476576 30762   oracle.xml.parser.v2.XSLExprValue
    1460840 36521   java.util.TreeMap
    1319360 23560   oracle.xml.parser.v2.XPathConstantExpr
    1054976 16484   org.jboss.mx.server.InvocationContext
    1001264 3546    * MethodDataKlass
    887424  11049   short[]
    835680  8705    java.lang.Class
    830208  25944   oracle.xml.util.NSNameImpl
    705816  29409   java.util.ArrayList
    684152  4501    org.jboss.web.tomcat.tc5.session.SessionBasedClusteredSession
    670288  14071   java.lang.Object[]
    640832  10013   oracle.xml.parser.v2.XPathVarReference
    561056  35066   javax.management.modelmbean.DescriptorSupport
    556272  23178   EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap$Entry
    552984  30451   java.lang.Class[]
    494760  2945    oracle.xml.parser.v2.XSLTemplate
    480792  20033   antlr.ANTLRHashString
    442576  27661   java.lang.Integer
    432096  4501    org.jboss.web.tomcat.statistics.ReplicationStatistics$TimeStatistic
    429040  10726   org.hibernate.hql.ast.tree.Node
    369880  9247    javax.management.modelmbean.ModelMBeanOperationInfo
    312384  19524   java.util.TreeMap$3
    305368  5453    java.net.URL
    287392  8981    org.jboss.mx.interceptor.ReflectedDispatcher
    259264  338     EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap$Entry[]
    252280  4505    org.jboss.cache.lock.ReadWriteLockWithUpgrade
    238600  5965    org.jboss.mx.interceptor.PersistenceInterceptor
    238600  5965    org.jboss.mx.interceptor.AttributeDispatcher
    236616  9859    org.jboss.mx.server.AbstractMBeanInvoker$OperationKey
    219776  3434    java.lang.reflect.Constructor
    206880  6465    javax.management.modelmbean.ModelMBeanAttributeInfo
    193168  2259    java.lang.reflect.Method[]
    173184  5412    java.lang.ref.SoftReference
    164920  589     oracle.xml.parser.v2.XSLStylesheet
    164464  541     * ObjArrayKlassKlass
    152832  6368    org.dom4j.tree.DefaultAttribute
    149472  2076    java.lang.reflect.Field
    144160  4505    org.jboss.cache.Node
    143160  5965    org.jboss.mx.interceptor.ModelMBeanAttributeInterceptor
    140600  3515    org.apache.xerces.dom.DeferredTextImpl
    140224  2740    javax.management.modelmbean.ModelMBeanAttributeInfo[]
    139056  7658    boolean[]
    134664  3359    java.lang.String[][]
    131936  1178    oracle.xml.parser.v2.XSLCondition
    131936  1178    oracle.xml.parser.v2.XSLForEach
    129072  2668    javax.management.modelmbean.ModelMBeanOperationInfo[]
    128952  5373    EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap$Entry
    124776  1733    org.hibernate.hql.ast.tree.IdentNode
    115200  1800    javax.management.modelmbean.ModelMBeanInfoSupport
    113088  2356    oracle.xml.parser.v2.AdditiveExpr
    109416  4559    java.beans.PropertyChangeSupport
    108960  1135    java.io.ObjectStreamClass
    108120  4505    org.jboss.cache.lock.IdentityLock
    105864  345     long[]
    98752   3086    java.io.ObjectStreamClass$WeakClassKey
    97968   4082    java.util.Vector
    96672   2014    java.util.Properties
    94240   589     oracle.xml.parser.v2.XSLOutput
    90072   3753    javax.management.ObjectName$Property
    87432   3643    javax.management.MBeanParameterInfo
    82368   858     org.hibernate.hql.ast.tree.DotNode
    81248   5078    java.lang.Long
    78656   1229    org.hibernate.mapping.Column
    77664   4854    java.util.Collections$SynchronizedSet
    77448   3227    java.util.LinkedList$Entry
    73824   769     org.jboss.mx.modelmbean.XMBean
    73536   4596    java.util.Hashtable$KeySet
    72144   4509    EDU.oswego.cs.dl.util.concurrent.CopyOnWriteArraySet
    72144   4509    EDU.oswego.cs.dl.util.concurrent.CopyOnWriteArrayList
    72144   4509    org.jboss.cache.Fqn
    72080   4505    org.jboss.cache.lock.ReadWriteLockWithUpgrade$WriterLock
    72080   4505    org.jboss.cache.lock.LockStrategyRepeatableRead
    72080   4505    org.jboss.cache.lock.ReadWriteLockWithUpgrade$ReaderLock
    72080   4505    org.jboss.cache.lock.LockMap
    72016   4501    org.apache.catalina.session.StandardSessionFacade
    71776   4486    java.io.FileDescriptor
    70680   589     oracle.xml.parser.v2.XSLCallTemplate
    70680   589     oracle.xml.parser.v2.XSLApplyTemplates
    70224   154     org.hibernate.persister.entity.SingleTableEntityPersister
    68296   2774    javax.management.ObjectName$Property[]
    68160   1065    org.apache.xerces.dom.DeferredElementNSImpl
    67760   770     org.hibernate.loader.entity.EntityLoader
    66992   19      EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap$Entry[]
    65968   1178    oracle.xml.parser.v2.XPathFilterExpr
    65968   589     oracle.xml.parser.v2.XMLUTF8Reader
    64432   4027    java.util.HashSet
    63648   1326    oracle.xml.parser.v2.XMLNode[]
    63440   1586    org.hibernate.loader.DefaultEntityAliases
    61256   589     oracle.xml.parser.v2.XSLNode
    61256   589     oracle.xml.parser.v2.XMLReader
    60816   2534    org.apache.xerces.xni.QName
    57360   478     org.hibernate.hql.ast.tree.FromElement
    56976   1187    org.hibernate.mapping.Property
    56544   1178    oracle.xml.parser.v2.XSLNodeSetExpr
    56544   1178    oracle.xml.parser.v2.MultiplicativeExpr
    56544   1178    oracle.xml.parser.v2.EqualExpr
    54384   618     oracle.xml.parser.v2.XMLError
    49392   2783    javax.management.MBeanParameterInfo[]
    47648   1489    java.util.LinkedHashMap$Entry
    47120   589     oracle.xml.parser.v2.XMLByteReader[]
    ...

  • 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

  • Memory leak using CWGraph

    I have a memory leak problem using the CWGraph control.
    I have an SDI application (MFC using Measurement Studio) and I generate dynamicaly a dialog containing a 2D Graph, and I use the OnTimer() of the dialog to generate data and to update the graph, with a timer of 50ms. In OnTimer() function I have a loop to generate
    and to update two plots on the graph. When I call a method of the graph (for example for changing the color of the plot or for updating a plot (using PlotXvsY)), I have a periodic increasing of memory with a fixed amount of memory (4k). In the same OnTimer() function I update also some CWSlide controls without memory leaks.
    If I comment the line that call a method of graph
    (ex. m_Graph.Plots.Item(1)....), the code works wi
    thout memory leaks.
    I'll apreciate any suggestion about this problem.

    I had the same memory leak problem with my program as well. I do not think it is because of using CWGraph. Memory leaks occur when you allocate memory and did not free them. The problem will accumulate and crashed randomly (sometime it crashed when you just move mouse around). Try this: if the program does not crash (memory leak crash) on the first time it compiles and runs, it is probable has nothing to do with the CWGraph. On the second and third run, if you did not free variable, the program will usually crashed. If your program crashed on the first time it runs, the problem might be something else.

  • Marshelling Web Service Response Memory Leak

    I believe I have found a memory leak when using the configuration below.
    The memory leak occurs when calling a web service. When the web service function is marshelling the response of the function call, an "500 Internal Server Error ... java.lang.OutOfMemoryError" is returned from OC4J. This error may be seen via the TCP Packet Monitor in JDeveloper.
    Unfortunately no exception dump is outputted to the OC4J log.
    Configuration:
    Windows 2000 with 1 gig ram
    JDeveloper 9.0.5.2 with JAX/RPC extension installed
    OC4J 10.0.3
    Sun JVM version 1.4.2_03-b02
    To demonstrate the error I created a simple web service and client. See below the client and web service function that demonstrates it.
    The web service is made up of a single function called "queryTestOutput".
    It returns an object of class "TestOutputQueryResult" which contains an int and an array.
    The function call accepts a one int input parameter which is used to vary the size of array in the returned object.
    For small int (less than 100). Web service function returns successfully.
    For larger int and depending on the size of memory configuration when OC4J is launched,
    the OutOfMemoryError is returned.
    The package "ws_issue.service" contains the web service.
    I used the Generate JAX-RPC proxy to build the client (found in package "ws_issue.client"). Package "types" was
    also created by Generate JAX-RPC proxy.
    To test the web service call execute the class runClient. Vary the int "atestValue" until error is returned.
    I have tried this with all three encodings: RPC/Encoded, RPC/Literal, Document/Literal. They have the
    same issue.
    The OutOfMemory Error is raised fairly consistently using the java settings -Xms386m -Xmx386m for OC4J when 750 is specified for the input parameter.
    I also noticed that when 600 is specified, the client seems to hang. According to the TCP Packet Monitor,
    the response is returned. But, the client seems unable to unmarshal the message.
    ** file runClient.java
    // -- this client is using Document/Literal
    package ws_issue.client;
    public class runClient
    public runClient()
    * @param args
    * Test out the web service
    * Play with the atestValue variable to until exception
    public static void main(String[] args)
    //runClient runClient = new runClient();
    long startTime;
    int atestValue = 1;
    atestValue = 2;
    //atestValue = 105; // last one to work with default memory settings in oc4j
    //atestValue = 106; // out of memory error as seen in TCP Packet Monitor
    // fails with default memory settings in oc4j
    //atestValue = 600; // hangs client (TCP Packet Monitor shows response)
    // when oc4j memory sessions are -Xms386m -Xmx386m
    atestValue = 750; // out of memory error as seen in TCP Packet Monitor
    // when oc4j memory sessions are -Xms386m -Xmx386m
    try
    startTime = System.currentTimeMillis();
    Ws_issueInterface ws = (Ws_issueInterface) (new Ws_issue_Impl().getWs_issueInterfacePort());
    System.out.println("Time to obtain port: " + (System.currentTimeMillis() - startTime) );
    // call the web service function
    startTime = System.currentTimeMillis();
    types.QueryTestOutputResponse qr = ws.queryTestOutput(new types.QueryTestOutput(atestValue));
    System.out.println("Time to call queryTestOutput: " + (System.currentTimeMillis() - startTime) );
    startTime = System.currentTimeMillis();
    types.TestOutputQueryResult r = qr.getResult();
    System.out.println("Time to call getresult: " + (System.currentTimeMillis() - startTime) );
    System.out.println("records returned: " + r.getRecordsReturned());
    for (int i = 0; i<atestValue; i++)
    types.TestOutput t = r.getTestOutputResults();
    System.out.println(t.getTestGroup() + ", " + t.getUnitNumber());
    catch (Exception e)
    e.printStackTrace();
    ** file wsmain.java
    package ws_issue.service;
    import java.rmi.RemoteException;
    import javax.xml.rpc.ServiceException;
    import javax.xml.rpc.server.ServiceLifecycle;
    public class wsmain implements ServiceLifecycle, ws_issueInterface
    public wsmain()
    public void init (Object p0) throws ServiceException
    public void destroy ()
    System.out.println("inside ws destroy");
    * create an element of the array with some hardcoded values
    private TestOutput createTestOutput(int cnt)
    TestOutput t = new TestOutput();
    t.setComments("here are some comments");
    t.setConfigRevisionNo("1");
    t.setItemNumber("123123123");
    t.setItemRevision("arev" + cnt);
    t.setTestGroup(cnt);
    t.setTestedItemNumber("123123123");
    t.setTestedItemRevision("arev" + cnt);
    t.setTestResult("testResult");
    t.setSoftwareVersion("version");
    t.setTestConditions("conditions");
    t.setStageName("world's a stage");
    t.setTestMode("Test");
    t.setTestName("test name");
    t.setUnitNumber("UnitNumber"+cnt);
    return t;
    * Web service function that is called
    * Create recCnt number of "records" to be returned
    public TestOutputQueryResult queryTestOutput (int recCnt) throws java.rmi.RemoteException
    System.out.println("Inside web service function queryTestOutput");
    TestOutputQueryResult r = new TestOutputQueryResult();
    TestOutput TOArray[] = new TestOutput[recCnt];
    for (int i = 0; i< recCnt; i++)
    TOArray = createTestOutput(i);
    r.setRecordsReturned(recCnt);
    r.setTestOutputResults(TOArray);
    System.out.println("End of web service function call");
    return r;
    * @param args
    public static void main(String[] args)
    wsmain wsmain = new wsmain();
    int aval = 5;
    try
    TestOutputQueryResult r = wsmain.queryTestOutput(aval);
    for (int i = 0; i<aval; i++)
    TestOutput t = r.getTestOutputResults();
    System.out.println(t.getTestGroup() + ", " + t.getUnitNumber());
    catch (Exception e)
    e.printStackTrace();
    ** file ws_issueInterface.java
    package ws_issue.service;
    import java.rmi.Remote;
    import java.rmi.RemoteException;
    public interface ws_issueInterface extends java.rmi.Remote
    public TestOutputQueryResult queryTestOutput (int recCnt) throws java.rmi.RemoteException;
    ** file TestOutputQueryResult.java
    package ws_issue.service;
    public class TestOutputQueryResult
    private long recordsReturned;
    private TestOutput[] testOutputResults;
    public TestOutputQueryResult()
    public long getRecordsReturned()
    return recordsReturned;
    public void setRecordsReturned(long recordsReturned)
    this.recordsReturned = recordsReturned;
    public TestOutput[] getTestOutputResults()
    return testOutputResults;
    public void setTestOutputResults(TestOutput[] testOutputResults)
    this.testOutputResults = testOutputResults;
    ** file TestOutput.java
    package ws_issue.service;
    public class TestOutput
    private String itemNumber;
    private String itemRevision;
    private String configRevisionNo;
    private String testName;
    private String testConditions;
    private String stageName;
    private String testedItemNumber;
    private String testedItemRevision;
    private String unitNumber;
    private String testStation;
    private String testResult;
    private String softwareVersion;
    private String operatorID;
    private String testDate; // to be datetime
    private String comments;
    private int testGroup;
    private String testMode;
    public TestOutput()
    public String getComments()
    return comments;
    public void setComments(String comments)
    this.comments = comments;
    public String getConfigRevisionNo()
    return configRevisionNo;
    public void setConfigRevisionNo(String configRevisionNo)
    this.configRevisionNo = configRevisionNo;
    public String getItemNumber()
    return itemNumber;
    public void setItemNumber(String itemNumber)
    this.itemNumber = itemNumber;
    public String getItemRevision()
    return itemRevision;
    public void setItemRevision(String itemRevision)
    this.itemRevision = itemRevision;
    public String getOperatorID()
    return operatorID;
    public void setOperatorID(String operatorID)
    this.operatorID = operatorID;
    public String getSoftwareVersion()
    return softwareVersion;
    public void setSoftwareVersion(String softwareVersion)
    this.softwareVersion = softwareVersion;
    public String getStageName()
    return stageName;
    public void setStageName(String stageName)
    this.stageName = stageName;
    public String getTestConditions()
    return testConditions;
    public void setTestConditions(String testConditions)
    this.testConditions = testConditions;
    public String getTestDate()
    return testDate;
    public void setTestDate(String testDate)
    this.testDate = testDate;
    public String getTestName()
    return testName;
    public void setTestName(String testName)
    this.testName = testName;
    public String getTestResult()
    return testResult;
    public void setTestResult(String testResult)
    this.testResult = testResult;
    public String getTestStation()
    return testStation;
    public void setTestStation(String testStation)
    this.testStation = testStation;
    public String getTestedItemNumber()
    return testedItemNumber;
    public void setTestedItemNumber(String testedItemNumber)
    this.testedItemNumber = testedItemNumber;
    public String getTestedItemRevision()
    return testedItemRevision;
    public void setTestedItemRevision(String testedItemRevision)
    this.testedItemRevision = testedItemRevision;
    public String getUnitNumber()
    return unitNumber;
    public void setUnitNumber(String unitNumber)
    this.unitNumber = unitNumber;
    public int getTestGroup()
    return testGroup;
    public void setTestGroup(int testGroup)
    this.testGroup = testGroup;
    public String getTestMode()
    return testMode;
    public void setTestMode(String testMode)
    this.testMode = testMode;

    Many thanks for your help.  This solved the issue for our .NET code, however the leak is still present in the report designer.  I was also wondering if you could help further: because of the limits on the java memory process is there a way to ensure that a separate java process is started for each report that is loaded in my report viewers collection?  Essentially the desktop application that i have created uses a tab control to display each type report, so each tab goes through the following code when displaying a report and closing a tab:
    Is there a way to ensure that a different Java process is kicked off each time that I display a different report?  My current code in c# always uses the same Java process so the memory ramps up.  The code to load the report and then dispose of the report through closing the tab (and now the Java process) looks like this:
        private void LoadCrystalReport(string FullReportName)
          ReportDocument reportDoc = new ReportDocument();
          reportDoc.Load(FullReportName, OpenReportMethod.OpenReportByTempCopy);
          this.crystalReportViewer1.ReportSource = reportDoc;
        private void DisposeCrystalReportObject()
          if (crystalReportViewer1.ReportSource != null)
            ReportDocument report = (ReportDocument)crystalReportViewer1.ReportSource;
            foreach (Table table in report.Database.Tables)
              table.Dispose();
            report.Database.Dispose();
            report.Close();
            report.Dispose();
            GC.Collect();
    Thanks

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

Maybe you are looking for

  • Boot device not found - Please install an operating system on your hard disk

    Trying to boot up this morning gave this error message: "Boot device not found Please install an operating system on your hard disk Hard Disk <3F0> F2  System Diagnostics" Pressing F2 brings up to  the "HP PC Hardware Diagnostics UEFI" page, where it

  • Quick look in Mail open's with the wrong application.

    When using quick look in Apple Mail, there is an option in the top right corner to open with, in my case, "Open with Adobe Acrobat." If I click and hold on this button, it brings a drop down menu allowing me to choose a different application. When I

  • Modify layout of a popup screen

    Hi Experts,   I need a modify a dialog screen( screen built using screen painter) in which data is displayed using table control. Since all the of columns in the table control is not visible in the popup and the user needs to scroll if he/she wants t

  • Post Increment Operator Question

    I had written a small program to test the working of Post increment operator. public static void main(String[] args)      int a = 4;      a = a++;      System.out.println ( a ); I expected the output to be '5', but the output given is '4'. Can anyone

  • Sending response to another BPEL from ESB

    I am passing request from esb to bpel and getting the response from bpel that i want to send to another bpel through esb. Everthing is working fine(not showing any error) but the response is not going to second bpel through.