aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Frame.dispose() - does this get rid of the frame in memory too? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Frame.dispose() - does this get rid of the frame in memory too?" Watch "Frame.dispose() - does this get rid of the frame in memory too?" New topic
Author

Frame.dispose() - does this get rid of the frame in memory too?

Rachel Swailes
Ranch Hand

Joined: May 18, 2004
Posts: 434
Hi there

I have an application where I need a non-modal dialog (the Address Book) to be displayed. Also, not more than one Address Book dialog may be open at a time.

So I made a function that is called when the user clicks on the Address Book button, to check if any Address Book dialog is currently open and if so to bring it to the front.



Then, I need to know when the Address Book dialog is closed by any means (for many reasons.) So I added a window listener to the Address Book.



But what I am finding is that when I close the dialog by any means and in doing so, call the two lines of code in endScreen() is that the dialog still exists. When I do Frame.getFrames() I still land up with an instance of AddressBookDialog that is aruond somewhere.

Can anyone explain why this AddressBook is hanging around and how I can make is hide and die quietly?

Many kind regards,
Rachel
Jkarthi keyan
Greenhorn

Joined: Apr 27, 2005
Posts: 3
The is code is partial so no one can find where is the error.

regards
Jkarthi
Rachel Swailes
Ranch Hand

Joined: May 18, 2004
Posts: 434
I appologise for posting partial code. I did no think that any other sections of this were relevant in finding the answer. Below I have also posted the code that is called when the Address Book button on the tool bar is pressed.



So to sum up, I have posted the code that gets called to show the new Address Book. This code checks if there is already a frame of the class AddressBookListener existing and if it does exist, that it should show the screen.

I also posted the code that is called when the frame is closed.

After the frame is closed, Frame.getFrames() still contains an instance of AddressBookListener which it should not.

I have posted the portions of the code that I think are relevant and I would be happy to post more if this is still not sufficient.

Many kind regards,
Rachel
[ May 09, 2005: Message edited by: Rachel Swailes ]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

frame.dispose() places a request to the Garbage Collector to free up the memory. When it gets deallocated is entirely up to the GC.


GenRocket - Experts at Building Test Data
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
'dispose' is a Window method, see api for details. In general, calling 'dispose' will remove a components peer. The Component will remain in the vm as long as there exists a reference to it. To remove the Component you set all/any references to it to 'null'.
Rachel Swailes
Ranch Hand

Joined: May 18, 2004
Posts: 434
Wow! It's only 8:30AM and already I have learned something new today. Thanks guys for your info and Craig, I always see you on the forums and your advice is always great!

Hope you have a super day.
Rachel
 
Consider Paul's rocket mass heater.
 
subject: Frame.dispose() - does this get rid of the frame in memory too?