Object Ownership

From Inkscape Wiki
Jump to navigation Jump to search


Inkscape currently uses garbage collecting to manage the lifetime of many objects. This is problematic...


Objects managed by GC: (grep -Ir GC:: src | grep public):

  • SPDocument: src/document.h
  • SPDesktop (via View): ui/view/view.h
  • Undo stack: undo-stack-observer.h
  • XML nodes: xml/event.h, xml/attribute-record.h, xml/composite-node-observer.h, xml/node.h, xml/simple-node-observer.h, xml/simple-node.h
  • Profile manager: profile-manager.h
  • Layer manager: layer-manager.h
  • Selections: selection.h
  • Document subset: document-subset.h

Document

Documents opened for editing should be owned by InkscapeApplication.

  • Help (tutorials)

Temporary documents should be opened with unique_ptr<>.

  • SVG Cursors (ui/cursor-utils.cpp, uses ink_file_open(), unique_ptr)
  • SVG to Pixbuf (ui/svg-renderer.cpp, uses ink_file_open(), unique_ptr)
  • SPDocument::copy (document.cpp, uses createDoc() ***)
  • Paint selector (ui/widget/paint-selector.cpp, uses SPDocument::createNewDoc, static, never deleted)
  • Markers (ui/widget/marker-combo-box.cpp, uses SPDocument::createNewDoc, static, never deleted)
  • Symbols (ui/dialog/symbols.cpp, uses SPDocument::createNewDoc() x3, not clear if any deleted)
  • Win32 File (ui/dialog/filedialogimpl-win32.cpp, uses SPDocument::createNewDoc(), unique_ptr)
  • About (ui/dialog/about.cpp, uses SPDocument::createNewDoc(), document not deleted!)
  • Paint servers (ui/dialog/paint-servers.cpp, uses SPDocument::createNewDoc(), not deleted!)
  • SVG Preview (ui/dialog/svg-preview.cpp, uses SPDocument::createNewDoc(), deleted in destructor)
  • Clipboard (ui/clipboard.cpp, uses SPDocument::createNewDoc(), uses std::unique_ptr)
  • InkView (inkview-window.h, uses SPDocument::createNewDoc(), not deleted!)
  • ink_file_new(), ink_file_open() (io/file.cpp, uses SPDocument::createNewDoc(), not deleted, utility for other functions)
  • CDR (extension/internal/cdr-input.cpp, uses SPDocument::createNewDocFromMem() x3, not deleted!)
  • SVG (extension/internal/svg.cpp, uses SPDocument::createNew() x3, SPDocument::createNewDocFromMem(), not deleted!)
  • PDF Input ...
  • PixBuf
  • WMF
  • WPG
  • Gimp Grad
  • EMF
  • VSD
  • DBUS
  • Cairo utils (display/cairo-utils.cpp, uses SPDocument::createNewDocFromMem(), uses std::unique_ptr)
  • Stock items (helper/stock-items.cpp, uses SPDocument::createNewDoc(), markers, static, not deleted).
  • URIReference (object/uri-reference.cpp, uses SPDocument::createChildDoc(),

One problem, when saving, a document is copied so it can be modified in place. This document stores a reference to the original document.

Inkscape::Application (different from InkscapeApplication) has a list of documents too. This list should be removed (as should Inkscape::Application).

Desktop

Desktop should be owned by InkscapeWindow. There should be no need to ref count.

The desktop is used in the following sources for these purpose:

  1. To find the SPDocument
  2. To ensure the pop-up window is over the correct window. As pop-up windows seize control, the desktop cannot disappear from beneath them.
  3. New layer pop-up where desktop is needed to add layer (why?).

GC is used in these files:

  • live_effects/parameter/powerstrokepointarray.cpp
  • ui/dialog/knot-properties.cpp (only in with Measure Tool). Removed
  • ui/dialog/layer-properties.cpp. Removed
  • ui/dialog/lpe-fillet-chamfer-properties.cpp. Removed.
  • ui/dialog/lpe-powerstroke-properties.cpp. Removed.
  • /ui/widget/style-subject.cpp (used by Fill and Stroke, and Layers dialogs for opacity, blending, and blurring).
  • src/widgets/desktop-widget.cpp
  • src/ui/view/view.cpp

Floating dialogs should be updated with a new desktop before a desktop is destroyed.

Undo stack

The undo stack should be owned by the document.

Selections

Selections should be owned by InkscapeWindow with an additional selection owned by InkscapeApplication for use with the GUI.

Life Cycle

OPEN INKSCAPE

InkscapeApplication::InkscapeApplication: Entrance
InkscapeApplication::InkscapeApplication: Exit
Application::Application: Entrance
Application::Application: Exit
SPDocument::SPDocument(): Entrance
SPDocument::SPDocument(): Exit
Selection::Selection
InkscapeWindow::InkscapeWindow: Entrance
  SPDesktopWidget::SPDesktopWidget(): Entrance
  SPDesktopWidget::SPDesktopWidget(): Exit
  SPDesktop::SPDesktop: entrance
    Selection::Selection
  SPDesktop::SPDesktop: exit
  SPDesktop::init(): entrance
  SPDesktop::init(): Exit
  SPDesktopWidget::on_realize: Entrance
  SPDesktopWidget::on_realize: Exit
InkscapeWindow::InkscapeWindow: Exit

ADD NEW DOCUMENT

SPDocument::SPDocument(): Entrance
SPDocument::SPDocument(): Exit
InkscapeWindow::InkscapeWindow: Entrance
  SPDesktopWidget::SPDesktopWidget(): Entrance
  SPDesktopWidget::SPDesktopWidget(): Exit
  SPDesktop::SPDesktop: entrance
    Selection::Selection
  SPDesktop::SPDesktop: exit
  SPDesktop::init(): entrance
    Selection::Selection
  SPDesktop::init(): Exit
  SPDesktopWidget::on_realize: Entrance
  SPDesktopWidget::on_realize: Exit
InkscapeWindow::InkscapeWindow: Exit

ADD DUPLICATE WINDOW

InkscapeWindow::InkscapeWindow: Entrance
  SPDesktopWidget::SPDesktopWidget(): Entrance
  SPDesktopWidget::SPDesktopWidget(): Exit
  SPDesktop::SPDesktop: entrance
    Selection::Selection
  SPDesktop::SPDesktop: exit
  SPDesktop::init(): entrance
  SPDesktop::init(): Exit
  SPDesktopWidget::on_realize: Entrance
  SPDesktopWidget::on_realize: Exit
InkscapeWindow::InkscapeWindow: Exit

REMOVE DUPLICATE WINDOW
InkscapeWindow::~InkscapeWindow: Entrance
InkscapeWindow::~InkscapeWindow: Exit
SPDesktopWidget::on_unrealize: Entrance
  SPDesktop::destroy()
    Selection::~Selection(): Entrance
    Selection::~Selection(): Exit
  SPDesktop::destroy(): Exit
SPDesktopWidget::on_unrealize: Exit
SPDesktopWidget::~SPDesktopWidget
SPDesktop::~SPDesktop

REMOVE NEW DOCUMENT WINDOW

InkscapeWindow::~InkscapeWindow: Entrance
InkscapeWindow::~InkscapeWindow: Exit
SPDesktopWidget::on_unrealize: Entrance
  SPDesktop::destroy()
    Selection::~Selection(): Entrance
    Selection::~Selection(): Exit
  SPDesktop::destroy(): Exit
SPDesktopWidget::on_unrealize: Exit
SPDesktopWidget::~SPDesktopWidget
SPDocument::~SPDocument(): Entrance
SPDocument::~SPDocument(): Exit
SPDesktop::~SPDesktop

CLOSE INKSCAPE

InkscapeWindow::~InkscapeWindow: Entrance
InkscapeWindow::~InkscapeWindow: Exit
SPDesktopWidget::on_unrealize: Entrance
  SPDesktop::destroy()
    Selection::~Selection(): Entrance
    Selection::~Selection(): Exit
  SPDesktop::destroy(): Exit
SPDesktopWidget::on_unrealize: Exit
SPDesktopWidget::~SPDesktopWidget
SPDocument::~SPDocument(): Entrance
SPDocument::~SPDocument(): Exit
SPDesktop::~SPDesktop


Application destructor not called! InkscapeApplication destructor not called!