When we define a new variable for frame it hold "null" value, but what it contain when we close that frame?

Recommended Answers

All 9 Replies

It still contains the same reference as that of before closing the window.
Closing the window or disposing the window doens't mean destroying the JFrame object.
We can make visible the window even after destroying it.

As destroying a window or closing it is just a operation performed on the window.

The jframe contains the same reference as before even we destory the window...

commented: Execellent +4

Interesting, i just checked it and it worked like u said.... then when JFRAME object free the resources..... I thought in java objects free the resources on close and make them null so we can use them later, start from basic intialization... But this thing make no sense.... even after closing the frame it is present and using the resources....

Any one there answer my this question... Y frame object isnt "null" y it has still resources....

Closing the window is just like any other operation performed on it like opening,resizing,minimizng,maximizing etc..

Just assume that closing the window is like somewhat similar to hiding the window.
So here in this case ,we are performing an simple close operation on window but the reference to that object still exists unless we explicitily make it null.

Think if i have 140 textfields , 200 buttons with images... and 10 frames in an app... then it would take almost all of my ram if java fail to clean the resources on close... kind of poor background for java.

One of the great advantages of java is built-in memory allocation and management.

if java fail to clean the resources on close... kind of poor background for java.

There is no question of java failing to clean the resources.
Once the application is closed and JVM starts quitting ,JVM is responsible to clean the memory and all the space allocated for JVM will automatically be deleted from RAM.
JVM is responsible for calling the garbage collector and looking all that..
While in C we should take care of memory management which increases programmers overhead.

Its one of the reasons that I like java because there is no pointers concept and i am not bothered with dealing the addresses...

@Majestics

Think if i have 140 textfields , 200 buttons with images... and 10 frames in an app... then it would take almost all of my ram if java fail to clean the resources on close... kind of poor background for java.


that valid for all programing languages

1/ top-level containers are never GC'ed, after GC returns only amounr of memory used for 2D Graphics more in English language http://stackoverflow.com/questions/6309407/remove-top-level-container-on-runtime

2/ dispose() in your case nothing returns, that's indicator and works just for JVM, and if you set JFrame.setDefaultClose....(JFrame.DISPOSE....), then after closing aplications JFrame no longer exist, otherwise is still presents in RAM until is PC restarted ...

3/ don't create lots of top-level Container, better would be create one JFrame and other windows could be JDialog or Jwindow

4/ you hard to set Focus, move to Front, overlay between two JFrames

5/ create only one JFrame and one/two JDialogs (modality, ... in API)
and reuse JDialog(s) by remove parent JPanel that contains JComponents
beware of using public static JComponent (remove only used memory myStaticComponent = null;), because never gone from memory until aplications exist in JVM,

6/ etc...

Thanx..... It mean i m not the only one who dont like work all time. ;-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.