Skip to content

Memory management

dimitar-asenov edited this page May 11, 2012 · 1 revision

Here are some rules and tips regarding memory management in Envision, C++ and Qt:

  1. Have a clear (ideally documented) ownership model, that defines responsibility for objects. It must be clear:
  • who owns an object?
  • when is an object deleted?
  • who and how deletes an object?
  1. Always delete objects derived from Item (QGraphicsItem) manually. Qt's documentation says this is more efficient compared to letting their parents delete them automatically in their destructor.
  2. Do not delete an Item in its own handler. Postpone the deletion until after the handler has finished executing.
  3. An Item should not contain other items directly, but only through pointers.
Clone this wiki locally