Skip to content

Widget needs a virtual destructor #112

@mrichards42

Description

@mrichards42

I've noticed memory usage creeping up the longer I run puzzles and little investigation revealed that widget subclass destructors aren't getting called, since Widget doesn't define a virtual constructor. For instance, Button never releases its Text widget.

Just adding virtual ~Widget(): pass doesn't compile, since that prevents Widget from getting an implicit move constructor, which is needed for Layout. Compilation error below:

In file included from ./remarkable_puzzles/vendor/rmkit/src/rmkit/ui/ui.cpy:4,
                 from ./remarkable_puzzles/vendor/rmkit/src/rmkit/rmkit.cpy:4:
./remarkable_puzzles/vendor/rmkit/src/rmkit/ui/dialog.cpy: In member function ‘virtual void ui::DialogBase::position_dialog()’:
./remarkable_puzzles/vendor/rmkit/src/rmkit/ui/dialog.cpy:55:74: error: use of deleted function ‘ui::VerticalLayout::VerticalLayout(ui::VerticalLayout&&)’
       v_layout := ui::VerticalLayout(0, 0, width, height, self.scene)
                                                                          ^
In file included from ./remarkable_puzzles/vendor/rmkit/src/rmkit/ui/pixmap.cpy:2,
                 from ./remarkable_puzzles/vendor/rmkit/src/rmkit/ui/button.cpy:2,
                 from ./remarkable_puzzles/vendor/rmkit/src/rmkit/ui/ui.cpy:3,
                 from ./remarkable_puzzles/vendor/rmkit/src/rmkit/rmkit.cpy:4:
./remarkable_puzzles/vendor/rmkit/src/rmkit/ui/layouts.cpy:64:9: note: ‘ui::VerticalLayout::VerticalLayout(ui::VerticalLayout&&)’ is implicitly deleted because the default definition would be ill-formed:
   class VerticalLayout: public AutoLayout:

I can get it to compile if I get rid of the Widget base class from Layout, which takes a little doing, but IMO would actually make sense anyways, though it's kind of a big change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions