Memory leakage problem with a database application

Discussion in 'Java' started by Devian, Sep 17, 2004.

  1. Devian

    Devian Guest

    Hi,

    I am getting OutOfMemory exception in my database application done
    with JBuilder 9.0.In that application a main frame which is a main
    window for that application has a jTree.When a tree node is clicked in
    that tree the related jFrame opens by finding the class.And when the
    opened frame closed dbDisposeMonitor(which is a member of the opened
    frame) works but the memory usage of the program never decreases.Some
    part of the suspicious code is here :


    // opens Frame
    // FormInfo is the selected node's related class it holds the frame
    name which will be opened

    private void OpenFrame(FormInfo f)
    {

    String sFullName = "package." + f.GetFormName();

    int iFrmIdx;
    for(iFrmIdx = 0; iFrmIdx < FRM_COUNT; ++iFrmIdx){
    // Forms is an FormInfo array which is defined in the class of
    main frame
    if(Forms[iFrmIdx] == null)
    continue;
    if(Forms[iFrmIdx].GetFormName().matches(f.GetFormName()))
    break;
    }

    try
    {
    // Frames is a MyFrame class(inherited by jFrame) whic is
    defined in the class of main frame
    Frames[iFrmIdx] = (MyFrame)
    Class.forName(sFullName).newInstance();
    Frames[iFrmIdx].SetFormIndex(iFrmIdx);
    Frames[iFrmIdx].setTitle(Forms[iFrmIdx].GetFormTitle());

    // The frame which is related to f will be kept in Frames
    array for disposing.

    Frames[iFrmIdx].pack();
    Frames[iFrmIdx].setBounds(jPanel1.getBounds());
    Frames[iFrmIdx].setLocationRelativeTo(jPanel1);
    Frames[iFrmIdx].show();

    f.SetOpenStatus(true);

    }
    catch(ClassNotFoundException eClsExc)
    {
    eClsExc.toString();
    }
    catch(InstantiationException eInsExc)
    {
    eInsExc.toString();
    }
    catch(IllegalAccessException eIllAcc)
    {
    eIllAcc.toString();
    }

    }


    While the opened frame is closing Frames[iFrmIdx] is set to null.And
    all of the components of the frame is set to null.But the memory
    leakage problem goes on.Finally gc() is closed after the frame closed
    but this dos not solve the problem.

    Any advice?

    Thanks
     
    Devian, Sep 17, 2004
    #1
    1. Advertising

  2. Devian wrote:
    >
    > While the opened frame is closing Frames[iFrmIdx] is set to null.And
    > all of the components of the frame is set to null.But the memory
    > leakage problem goes on.Finally gc() is closed after the frame closed
    > but this dos not solve the problem.
    >


    Are you sure you're calling dispose() on the frame before setting it to
    null ?

    BK
     
    Babu Kalakrishnan, Sep 17, 2004
    #2
    1. Advertising

  3. Devian

    Devian Guest

    Babu Kalakrishnan <> wrote in message news:<>...
    > Devian wrote:
    > >
    > > While the opened frame is closing Frames[iFrmIdx] is set to null.And
    > > all of the components of the frame is set to null.But the memory
    > > leakage problem goes on.Finally gc() is closed after the frame closed
    > > but this dos not solve the problem.
    > >

    >
    > Are you sure you're calling dispose() on the frame before setting it to
    > null ?
    >
    > BK


    I'm calling dispose() in WindowClosing function of the frame then I
    set Frames[iFrmIdx] to null.Frames[iFrmIdx] is in the main frame and
    defined static to reach from the opened frame.
     
    Devian, Sep 17, 2004
    #3
  4. Devian

    Paul Lutus Guest

    Devian wrote:

    / ...

    > I'm calling dispose() in WindowClosing function of the frame then I
    > set Frames[iFrmIdx] to null.Frames[iFrmIdx] is in the main frame and
    > defined static to reach from the opened frame.


    This is not very clear. You may want to confirm whether the dispose()
    operation is always executed, in all cases, and before the null setting
    operation. If necessary, put debugging calls into the code to verify that
    this sequence is always followed.

    --
    Paul Lutus
    http://www.arachnoid.com
     
    Paul Lutus, Sep 17, 2004
    #4
  5. Devian wrote:
    > Babu Kalakrishnan <> wrote in message news:<>...
    >>
    >>> While the opened frame is closing Frames[iFrmIdx] is set to null.And
    >>>all of the components of the frame is set to null.But the memory
    >>>leakage problem goes on.Finally gc() is closed after the frame closed
    >>>but this dos not solve the problem.
    >>>

    >>
    >>Are you sure you're calling dispose() on the frame before setting it to
    >>null ?

    >
    >
    > I'm calling dispose() in WindowClosing function of the frame then I
    > set Frames[iFrmIdx] to null.Frames[iFrmIdx] is in the main frame and
    > defined static to reach from the opened frame.
    >


    Then it is almost certainly due to some strong reference maintained by
    another live object. The reference need not be of the Frame itself, but
    could even be to one of the components contained in the frame (because
    then the Frame can be reached by tracing recursively through the
    "parent" member of the component) or even an anonymous class declared
    within your Frame (which will hold a reference to the containing instance).

    Using a memory profiler should aid in debugging this.

    BK
     
    Babu Kalakrishnan, Sep 18, 2004
    #5
  6. Devian

    Devian Guest

    Hi,

    BK I write a simple application to test my real application's logic
    and in that application I'm facing the same problem again.I want to
    tell about this program.I have a main frame(Frame2) and in that frame
    Frame1 is opened by clicking the related treenode.Frame1's close
    operation is set to DISPOSE_ON_CLOSE and Frame1 has a dispose
    monitor.When Frame1 is opened memory usage is increasing but when
    Frame1 is closed by clicking X button of the window memory never
    released.I dont understand what I'm doing wrong?Here is the code of
    Frame2:

    public class Frame2 extends JFrame {
    XYLayout xYLayout1 = new XYLayout();


    Frame1 frm = null;
    JScrollPane jScrollPane1 = new JScrollPane();
    DefaultMutableTreeNode trNavForms = new
    DefaultMutableTreeNode("User Forms");
    JTree jTree1 = new JTree(trNavForms);
    databaseapp.NodeInfo fTemp = new NodeInfo();
    }
     
    Devian, Sep 18, 2004
    #6
  7. Devian

    Devian Guest

    (Devian) wrote in message news:<>...
    > Hi,
    >
    > BK I write a simple application to test my real application's logic
    > and in that application I'm facing the same problem again.I want to
    > tell about this program.I have a main frame(Frame2) and in that frame
    > Frame1 is opened by clicking the related treenode.Frame1's close
    > operation is set to DISPOSE_ON_CLOSE and Frame1 has a dispose
    > monitor.When Frame1 is opened memory usage is increasing but when
    > Frame1 is closed by clicking X button of the window memory never
    > released.I dont understand what I'm doing wrong?Here is the code of
    > Frame2:
    >
    > public class Frame2 extends JFrame {
    > XYLayout xYLayout1 = new XYLayout();
    >
    >
    > Frame1 frm = null;
    > JScrollPane jScrollPane1 = new JScrollPane();
    > DefaultMutableTreeNode trNavForms = new
    > DefaultMutableTreeNode("User Forms");
    > JTree jTree1 = new JTree(trNavForms);
    > databaseapp.NodeInfo fTemp = new NodeInfo();
    > }


    Sorry for not posting the whole code.I think I did something wrong
    while posting the code.The remaining suspicious part is here :


    void jTree1_valueChanged(TreeSelectionEvent e) {
    DefaultMutableTreeNode SelectedNode =
    (DefaultMutableTreeNode)jTree1.getLastSelectedPathComponent();

    TreePath pathnode = (TreePath)jTree1.getLeadSelectionPath();
    String strNode = new String();
    strNode = SelectedNode.toString();


    if(strNode.matches("Frame1")){
    frm = new Frame1();
    frm.pack();
    frm.setLocation(jPanel1.getLocation());
    frm.setBounds(jPanel1.getBounds());
    frm.show();

    }
    }

    And Frame1's windowclosing event :

    void this_windowClosing(WindowEvent e) {
    jdbNavField1.setDataSet(null);
    jdbNavToolBar1.setDataSet(null);
    jdbStatusLabel1.setDataSet(null);
    jdbTable1.setDataSet(null);
    jdbTextField1.setDataSet(null);
    this.dispose();
    this.removeAll();
    }
     
    Devian, Sep 19, 2004
    #7
  8. Devian wrote:
    > (Devian) wrote in message news:<>...
    >
    >>BK I write a simple application to test my real application's logic
    >>and in that application I'm facing the same problem again.I want to
    >>tell about this program.I have a main frame(Frame2) and in that frame
    >>Frame1 is opened by clicking the related treenode.Frame1's close
    >>operation is set to DISPOSE_ON_CLOSE and Frame1 has a dispose
    >>monitor.When Frame1 is opened memory usage is increasing but when
    >>Frame1 is closed by clicking X button of the window memory never
    >>released.I dont understand what I'm doing wrong?Here is the code of
    >>Frame2:
    >>


    Without sample code that can be compiled and run on my machine, I cannot
    unfortunately check if your code does exhibit a memory leak or not.

    However, just want to clarify one thing - when you refer to your problem
    a "memory leak", how are you defining a memory leak ? The above
    observation (about memory usage increasing when Frame1 is opened but not
    decreasing when the frame is disposed) is pretty standard behaviour for
    most JVMs if you're only looking at the total memory used by the JVM.
    Most of the JVM implementations I've seen don't release memory back to
    the OS every time the memory requirement shrinks.

    What you'd want to check is if memory requirement continues to increase
    if you repeatedly open and dispose these frames (eventually resulting in
    a OutOfMemoryError). Also at least on the sun JVMs you can observe the
    reduction in memory usage by invoking GC manually and checking if the
    "used" memory reduces (The difference between the results of the
    totalMemory and freeMemory methods of the Runtime class).

    BK
     
    Babu Kalakrishnan, Sep 20, 2004
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gaël

    w3wp crash and memory leakage

    Gaël, Oct 15, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    2,729
    Alvin Bruney
    Oct 16, 2003
  2. John Hilton

    How to identify the memory leakage...

    John Hilton, Dec 16, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    329
    John Hilton
    Dec 16, 2004
  3. Sambucus
    Replies:
    19
    Views:
    903
    George Neuner
    May 6, 2004
  4. chets

    memory leakage problem

    chets, Oct 30, 2006, in forum: C Programming
    Replies:
    2
    Views:
    295
    Simon Biber
    Oct 31, 2006
  5. luke

    Memory leakage problem

    luke, May 1, 2008, in forum: C++
    Replies:
    5
    Views:
    335
Loading...

Share This Page