Thread View: borland.public.jbuilder.java.swing
2 messages
2 total messages
Started by Adrian Pitulac
Sat, 03 Jan 2004 13:32
Swing Application Hangups (Garbage Collection?)
Author: Adrian Pitulac
Date: Sat, 03 Jan 2004 13:32
Date: Sat, 03 Jan 2004 13:32
37 lines
2193 bytes
2193 bytes
Hello, i have a problem with one of my applications which seems to hangup. i have looked with optimizeit on the app and it seems that the garbage collection takes very long time. now let me explain my application arhitecture: it has an login frame which starts first. here you can select one specific application module which will be launched after login. a have an application module which works fine. my problem is that in any module i need to have an option to close that module and open the login frame. my module is also based on a frame. my application hangs after 3-4 cycles of LOGIN -> CLOSE MODULE -> LOGIN ................................ my LOGIN frame initializes the MODULE frame with some code like: frm.pack(); frm.validate(); frame_pos_size.frame_pos_size(frm,true); this.dispose(); my MODULE frame closes itself and initializes LOGIN frame with some code like: ids_login frm = new ids_login(); frm.pack(); frm.validate(); frame_pos_size.frame_pos_size(frm,true); this.dispose(); Please tell me what to try to solve this problem. Did i misunderstood the concept of "disposing" a frame? Thanks very much! Adrian
Re: Swing Application Hangups (Garbage Collection?)
Author: Tad Frysinger [TeamB]
Date: Wed, 14 Jan 2004 19:36
Date: Wed, 14 Jan 2004 19:36
72 lines
3785 bytes
3785 bytes
Adrian -
dispose() causes all native resources (i.e. handles, graphics resources,
etc.) to be released back to the underlying OS. I'm not sure what is
causing your hangup, but I'll bet somehow you have a reference between
those two frames, so they are each holding on to a hard reference to
something causing a deadlock.
You can also structure your main app to switch between login and module
frames in a number of ways. Here is one:
public class Examples {
boolean packFrame = false;
//Construct the application
public Examples() {
ModuleFrame module = null; // Interface, hopefully!
LoginFrame l = new LoginFrame(); // login frame
l.pack();
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = l.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
l.setLocation( (screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
boolean keepGoing = true;
while ( keepGoing ) {
l.setVisible(true);
// Login is now visible. When it is closed, the user has indicated
// somehow what action should be taken, including whether to end
// the application, or open a new module. hide() is used, not
// displose()
switch ( l.getUserAction ) {
case LoginFrame.CLOSE_APPLICATION :
keepGoing = false;
break;
case LoginFrame.EXEC_MODULE :
// Determine the module, credentials, etc. and instance the
// appropriate ModuleFrame. This could be done generically
// using Java reflection, or specifically if the modules
// are unlikely to change.
ModuleFrame frame = (ModuleFrame)<mechanism of choice>;
frame.setVisible( true );
// Determine if close means close the app or not, and
// take appropriate action
break;
case LoginFrame.PASSWORD_EXCEPTION :
// etc.
}
}
//Main method
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {
e.printStackTrace();
}
new Examples();
}
}
--
Tad Frysinger [TeamB]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads