Object Ownership

From Inkscape Wiki
Revision as of 08:17, 5 September 2021 by Tavmjong (talk | contribs)
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


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)

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