Gtk4 Gtk.PopoverMenu.new_from_model_full fails in gjs



I am trying to create a popovermenu that is nested instead of the sliding menus created by default in Gtk4. Using the method Gtk.PopoverMenu.new_from_model_full(giomenumodel, Gtk.PopoverMenuFlags.NESTED) lead to errors and fails-

(gjs:153067): Gjs-CRITICAL **: 19:28:11.268: Object Gtk.PopoverMenu (0x5566cb88c470), has been already finalized — impossible to access it. This might be caused by the object having been destroyed from C code using something such as destroy(), dispose(), or remove() vfuncs.

(gjs:153067): Gjs-CRITICAL **: 19:28:14.653: Object 0x5566cb88c8f0 of type GtkPopoverMenu has been finalized while it was still owned by gjs, this is due to invalid memory management.

Is this a problem with gjs, gtk4 or the way I am using the method? Any suggestions?

A small program demonstrating the errors, at least on my system is attached. It can be run from the command line.

#!/usr/bin/env gjs = "4.0";
const { Gio, Gtk } =;

class ImageViewerWindow {
    constructor(app) {
        this._app = app;
        this._window = null;
        this._box = null;
        this._fileChooserButton = null;

    _buildUI() {
        this._window = new Gtk.ApplicationWindow({
            application: this._app,
            defaultHeight: 600,
            defaultWidth: 800
        this._box = new Gtk.Box({
            orientation: Gtk.Orientation.VERTICAL

        this._fileChooserButton = Gtk.Button.new_with_label('Menu');

        this._fileChooserButton.connect('clicked', (button) => {
            //this.popupmenu = Gtk.PopoverMenu.new_from_model(this.desktopBackgroundGioMenu);
            this.popupmenu = Gtk.PopoverMenu.new_from_model_full(this.desktopBackgroundGioMenu, Gtk.PopoverMenuFlags.NESTED);


        this.desktopBackgroundGioMenu =;

        this.desktopBackgroundGioMenu.append("New Folder", "app.doNewFolder");

        this.pasteUndoRedoMenu =;
        this.pasteUndoRedoMenu.append("Paste", "app.doPaste");
        this.pasteUndoRedoMenu.append("Undo", "app.doUndo");
        this.pasteUndoRedoMenu.append("Redo", "app.doRedo");

        this.desktopBackgroundGioMenu.append_submenu("Paste Menu", this.pasteUndoRedoMenu);

    getWidget() {
        return this._window;

const application = new Gtk.Application({
    application_id: 'org.gnome.Sandbox.MenuExample',
    flags: Gio.ApplicationFlags.FLAGS_NONE

application.connect('activate', app => {
    let activeWindow = app.activeWindow;

    if (!activeWindow) {
        let imageViewerWindow = new ImageViewerWindow(app);
        activeWindow = imageViewerWindow.getWidget();


It’s a GTK issue.

Thanks for the info and for the fix!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.