TN011: Layout Managers

When you use setLayout or setConstraint, you must to specify a pointer to a Layout or a Constraint respectively.

These pointers are deleted automatically when the widget is destroyed, but they're not destroyed when you change the layout manager or the constraint. E.g.:

  {
    Layout* betterLayout = new MyBetterLayout();
    ...
    {
      Frame frame(...);
      frame.setLayout(new MyLayout(...));
      MyLayout* oldLayout = frame.setLayout(betterLayout);

      delete oldLayout; // <-- we must to destroy the layout: it isn't 
                        //     deleted automatically because it isn't
                        //     the 'frame' layout manager anymore
    }
    ...
    // here betterLayout doesn't exist (was automatically deleted 
    // in the Frame destructor)
  }

Remember to use the following code if you make instances of Layout (or Constraint) in the stack:

  {
    Frame frame(...);
    ClientLayout layout;
    frame.setLayout(&layout);
    ...
    frame.setLayout(NULL); // you have to do this because "layout" would be
                           // deleted in ~Frame() by second time
  }

See also:
Layout, Constraint, Widget::setLayout, Widget::setConstraint