private static void cleanup() {
        try {
            if (g != null) 
                g.dispose();
            
            if (layout != null) 
                layout.close();
            
            if (analyzer != null) 
                analyzer.close();
            
            if (mediator != null) 
                mediator.close();
            
            g = null;
            layout = null;
            analyzer = null;
            mediator = null;
        } catch (Exception ex) {
            throw new RuntimeException("Unrecoverable error trying to clean up Tesseract references", ex);
        }
    }