Memory leakage problem with a database application

D

Devian

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
 
B

Babu Kalakrishnan

Devian said:
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
 
D

Devian

Babu Kalakrishnan said:
Devian said:
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.
 
P

Paul Lutus

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

Babu Kalakrishnan

Devian said:
Babu Kalakrishnan said:
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
 
D

Devian

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();
}
 
D

Devian

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();
}
 
B

Babu Kalakrishnan

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top