2

When you create a GUI element such as a JFrame like this

new JFrame(); // nothing pointing to it.

is this wrong because there is nothing pointing to it, so it will be garbage collected. I realize this works, but I want to make sure this works all the time, even if the garbage collector runs.

1
  • JFrame missed method finalize(), then never will be GC'ed Commented Apr 5, 2012 at 5:19

1 Answer 1

2

You don't need to save a reference variable that refers to the JFrame object (unless you want to use it later). All you need is to call the constructor JFrame(), and the window will be constructed. Hence, in all cases, it should work without any problem.

Sign up to request clarification or add additional context in comments.

2 Comments

Does it create an internal reference somewhere?
Can you provide some more info? Why doesnt the collector grab it? From my understanding anything lacking a referring pointer in the current execution stack will be lost..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.