This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes confusion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

confusion

Inder Kumar Rathore
Ranch Hand

Joined: Apr 14, 2010
Posts: 41

here is a piece of code

view plaincopy to clipboardprint?

1. import java.awt.*;
2. import java.awt.event.*;
3.
4. public class Activator {
5. public static void main(String[] args) {
6. Button b;
7. ActionListener al = new MyActionListener();
8. Frame f = new Frame("Hello Java");
9. f.add(b = new Button("Hello"),BorderLayout.NORTH);
10. b.addActionListener(al);
11. f.add(b = new Button("OK"), BorderLayout.CENTER);
12. b.addActionListener(al);
13. f.add(b = new Button("Quit"),BorderLayout.SOUTH);
14. b.addActionListener(al);
15. f.pack();
16. f.show();
17. }
18. }

import java.awt.*; import java.awt.event.*; public class Activator { public static void main(String[] args) { Button b; ActionListener al = new MyActionListener(); Frame f = new Frame("Hello Java"); f.add(b = new Button("Hello"),BorderLayout.NORTH); b.addActionListener(al); f.add(b = new Button("OK"), BorderLayout.CENTER); b.addActionListener(al); f.add(b = new Button("Quit"),BorderLayout.SOUTH); b.addActionListener(al); f.pack(); f.show(); } }


My question is that the reference b is assigned Button object three times...and the first two buttons "Hello" and "OK" are not referenced by any references..
Now as they are not referenced by any reference, so garbage collector may collects its memory, resulting in loss of these two buttons.....
Am I right or not???

Please comment......

Thanks

Living is easy with your eyes closed.....
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

Closing this cross-post.
Please keep discussion in your original post.


OCUP UML fundamental and ITIL foundation
youtube channel
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: confusion
 
Similar Threads
Event
Is it a source of bug?
ANONYMOUS CLASS
Unable to create an instance!!
Problem regarding Border Layout