Skip to content
  • Luca Bacci's avatar
    modern-gtk2: Delay construction of Gtk::TreeModel* objects (!17) · c602170f
    Luca Bacci authored and Mike Fleetwood's avatar Mike Fleetwood committed
    C++ initialises static member variables before main() is called.
    Therefore the static members of:
        struct Slots
        {
            static Gtk::TreeModelColumn<Glib::ustring> text;
            static Gtk::TreeModelColumn<bool> sensitive;
        private:
            static Gtk::TreeModel::ColumnRecord record_;
        };
    are constructed before Gtk::Main() is called in main().  However the
    Gtkmm documentation specifically says that they must be constructed
    afterwards [1].
    
    Resolve this by using the Construct On First Use Idiom [2] to delay
    initialisation until the slots are first used.  Normally this idiom uses
    static local objects, however it is being applied to class static
    objects here because the objects are accessed in many methods.  The
    downside of this approach is that the objects are never destructed,
    which memory analysers like Valgrind could see as a memory leak, but
    that is actually deliberate.  That leak can be removed once we can use
    C++11 and std:...
    c602170f