Memory Frame

This component will show the memory usage in a window frame and provide a Java method for a foreign predicate to show the window frame. The memory frame has its own constructor which will place a memory panel inside the memory frame. The main method visible from Prolog is the startMonitor() method. This method will create a memory frame and a frame thread. It will then make the memory frame visible and start the frame thread:

     * <p>Java method called from Prolog.</p>
    public static void startMonitor() {
        MemoryFrame frame = new MemoryFrame();
        frame.setSize(500, 300);
        frame.thread = new ThreadFrame(frame);

We use a little Prolog text ‘memory.p’ to register the Java method as a foreign predicate. This Prolog text can be consulted from within the development environment. When doing so the JFreeChart libraries and the code for the class of this example have to be available. More details on what has to go into the class path can be found in the appendix. The main statement of the Prolog text reads as follows:

:- foreign(start_monitor/0, '', startMonitor).

The Prolog text also registers a foreign predicate gc/0 that maps to the Java method System.gc(). We can experiment with calling explicitly the garbage collection. The Jekejeke Prolog system does in no place call the garbage collection, and it is not recommended to include explicit calls since the virtual machine might anyway ignore it.