When you don't need to use a Browser instance you must dispose it using the Browser.dispose() method.


For example: 

browser.dispose();


Accessing disposed instance

Once you dispose a Browser instance, you cannot use it anymore. If you try to access already disposed Browser instance the IllegalStateException exception will be thrown. For example: 

browser.dispose();
browser.getDocument(); // IllegalStateException will be thrown

To check if the Browser instance is disposed or not, you can use the Browser.isDisposed() method.


Dispose events

Each Browser instance can be also disposed from JavaScript via the window.close() function. In this case you might be interested in receiving notification when a Browser instance is disposed. To get such notifications, you can use DisposeListener. For example: 

browser.addDisposeListener(new DisposeListener<Browser>() {
    @Override
    public void onDisposed(DisposeEvent<Browser> event) {
        // Browser is disposed
    }
});

When you dispose a Browser instance manually via the Browser.dispose() method, the Dispose event will also be fired.