Seeing memory usage increase does not mean that there's a memory leak. The program may use more memory because it has to create temporary objects for event dispatching or repainting. These temporary objects are short-lived and are removed by the garbage collector in a short period of time; so the memory used by them becomes available for the program again.
You won't see this with process monitoring tools though since the memory is not returned to the OS; the JVM reserves it for future use. You can use tools like VisualVM to monitor the actual memory use of the program.
Are there any better ways to simply display a JFrame?
The code that you post is actually incorrect; you shouldn't create and manipulate GUI objects from the program's main thread. Here's a correct example of displaying a JFrame
from the Java Tutorial:
import javax.swing.*;
public class HelloWorldSwing {
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("HelloWorldSwing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Add the ubiquitous "Hello World" label.
JLabel label = new JLabel("Hello World");
frame.getContentPane().add(label);
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}