basctl/source/dlged/dlged.cxx                                     |   30 
 basctl/source/dlged/dlgedfac.cxx                                  |   20 
 basctl/source/dlged/dlgedobj.cxx                                  |   10 
 basctl/source/inc/dlged.hxx                                       |    2 
 basctl/source/inc/dlgedfac.hxx                                    |    2 
 basctl/source/inc/dlgedobj.hxx                                    |    8 
 chart2/source/controller/dialogs/tp_3D_SceneIllumination.cxx      |    1 
 chart2/source/controller/drawinglayer/ViewElementListProvider.cxx |   10 
 chart2/source/controller/main/ChartController_Tools.cxx           |    6 
 chart2/source/controller/main/DrawCommandDispatch.cxx             |   18 
 chart2/source/controller/main/DrawCommandDispatch.hxx             |    3 
 chart2/source/view/main/ChartView.cxx                             |    3 
 chart2/source/view/main/ShapeFactory.cxx                          |    4 
 compilerplugins/clang/refcounting.cxx                             |   13 
 compilerplugins/clang/test/refcounting.cxx                        |   17 
 compilerplugins/clang/weakobject.cxx                              |    1 
 cui/source/tabpages/tpline.cxx                                    |   32 
 cui/source/tabpages/tplneend.cxx                                  |    6 
 filter/source/msfilter/escherex.cxx                               |    4 
 filter/source/msfilter/msdffimp.cxx                               |  119 +-
 filter/source/msfilter/svdfppt.cxx                                |  101 +-
 filter/source/svg/svgexport.cxx                                   |    4 
 filter/source/svg/svgfilter.cxx                                   |    8 
 framework/source/fwe/helper/undomanagerhelper.cxx                 |    2 
 include/filter/msfilter/msdffimp.hxx                              |   19 
 include/filter/msfilter/svdfppt.hxx                               |   14 
 include/svx/EnhancedCustomShape2d.hxx                             |    8 
 include/svx/compressgraphicdialog.hxx                             |    2 
 include/svx/connctrl.hxx                                          |    2 
 include/svx/cube3d.hxx                                            |    4 
 include/svx/dlgctl3d.hxx                                          |   10 
 include/svx/dlgctrl.hxx                                           |   12 
 include/svx/extedit.hxx                                           |    6 
 include/svx/fmdpage.hxx                                           |    2 
 include/svx/fmobjfac.hxx                                          |    4 
 include/svx/fmpage.hxx                                            |    2 
 include/svx/fmview.hxx                                            |   10 
 include/svx/fontworkgallery.hxx                                   |    4 
 include/svx/lathe3d.hxx                                           |    6 
 include/svx/measctrl.hxx                                          |    2 
 include/svx/obj3d.hxx                                             |    6 
 include/svx/objfac3d.hxx                                          |    4 
 include/svx/scene3d.hxx                                           |   10 
 include/svx/sdr/table/tablecontroller.hxx                         |    8 
 include/svx/selectioncontroller.hxx                               |    3 
 include/svx/sphere3d.hxx                                          |    4 
 include/svx/svdcrtv.hxx                                           |    4 
 include/svx/svddrgmt.hxx                                          |    4 
 include/svx/svdedtv.hxx                                           |    2 
 include/svx/svdedxv.hxx                                           |    5 
 include/svx/svdetc.hxx                                            |    4 
 include/svx/svdmodel.hxx                                          |    7 
 include/svx/svdoashp.hxx                                          |   10 
 include/svx/svdobj.hxx                                            |   59 -
 include/svx/svdocapt.hxx                                          |    4 
 include/svx/svdocirc.hxx                                          |    4 
 include/svx/svdoedge.hxx                                          |    6 
 include/svx/svdograf.hxx                                          |    6 
 include/svx/svdogrp.hxx                                           |    9 
 include/svx/svdomeas.hxx                                          |    8 
 include/svx/svdomedia.hxx                                         |    2 
 include/svx/svdoole2.hxx                                          |    8 
 include/svx/svdopage.hxx                                          |    2 
 include/svx/svdopath.hxx                                          |    6 
 include/svx/svdorect.hxx                                          |    4 
 include/svx/svdotable.hxx                                         |    2 
 include/svx/svdotext.hxx                                          |   14 
 include/svx/svdouno.hxx                                           |    7 
 include/svx/svdoutl.hxx                                           |    4 
 include/svx/svdovirt.hxx                                          |    6 
 include/svx/svdpage.hxx                                           |   11 
 include/svx/svdundo.hxx                                           |   20 
 include/svx/unopage.hxx                                           |    2 
 include/svx/unoshape.hxx                                          |   14 
 include/svx/view3d.hxx                                            |    2 
 include/unotools/weakref.hxx                                      |    7 
 reportdesign/inc/RptObject.hxx                                    |   22 
 reportdesign/inc/RptPage.hxx                                      |    2 
 reportdesign/source/core/api/Shape.cxx                            |    2 
 reportdesign/source/core/inc/ReportDrawPage.hxx                   |    2 
 reportdesign/source/core/sdr/ReportDrawPage.cxx                   |    2 
 reportdesign/source/core/sdr/RptObject.cxx                        |   44 -
 reportdesign/source/core/sdr/RptPage.cxx                          |   13 
 reportdesign/source/core/sdr/UndoActions.cxx                      |    6 
 reportdesign/source/ui/inc/UITools.hxx                            |    2 
 reportdesign/source/ui/inc/dlgedfac.hxx                           |    2 
 reportdesign/source/ui/misc/RptUndo.cxx                           |    7 
 reportdesign/source/ui/misc/UITools.cxx                           |    4 
 reportdesign/source/ui/report/ReportController.cxx                |   27 
 reportdesign/source/ui/report/ReportSection.cxx                   |   10 
 reportdesign/source/ui/report/ViewsWindow.cxx                     |    8 
 reportdesign/source/ui/report/dlgedfac.cxx                        |    6 
 sc/CppunitTest_sc_shapetest.mk                                    |    1 
 sc/inc/postit.hxx                                                 |  109 --
 sc/qa/extras/anchor.cxx                                           |    5 
 sc/qa/unit/scshapetest.cxx                                        |   12 
 sc/qa/unit/ucalc.cxx                                              |   46 -
 sc/qa/unit/ucalc_sort.cxx                                         |    6 
 sc/source/core/data/documen9.cxx                                  |    4 
 sc/source/core/data/drwlayer.cxx                                  |   50 -
 sc/source/core/data/postit.cxx                                    |  422 
----------
 sc/source/core/tool/detfunc.cxx                                   |   34 
 sc/source/filter/excel/xiescher.cxx                               |  100 +-
 sc/source/filter/inc/xcl97rec.hxx                                 |    2 
 sc/source/filter/inc/xiescher.hxx                                 |   32 
 sc/source/filter/rtf/eeimpars.cxx                                 |    4 
 sc/source/ui/drawfunc/fuconarc.cxx                                |    4 
 sc/source/ui/drawfunc/fuconcustomshape.cxx                        |    4 
 sc/source/ui/drawfunc/fuconpol.cxx                                |    4 
 sc/source/ui/drawfunc/fuconrec.cxx                                |    4 
 sc/source/ui/drawfunc/fuconuno.cxx                                |    4 
 sc/source/ui/drawfunc/fuins1.cxx                                  |    8 
 sc/source/ui/drawfunc/fuins2.cxx                                  |   14 
 sc/source/ui/drawfunc/fupoor.cxx                                  |    2 
 sc/source/ui/drawfunc/futext.cxx                                  |    4 
 sc/source/ui/drawfunc/graphsh.cxx                                 |   14 
 sc/source/ui/inc/fuconarc.hxx                                     |    2 
 sc/source/ui/inc/fuconcustomshape.hxx                             |    2 
 sc/source/ui/inc/fuconpol.hxx                                     |    2 
 sc/source/ui/inc/fuconrec.hxx                                     |    2 
 sc/source/ui/inc/fuconuno.hxx                                     |    2 
 sc/source/ui/inc/fupoor.hxx                                       |    2 
 sc/source/ui/inc/futext.hxx                                       |    2 
 sc/source/ui/inc/notemark.hxx                                     |    2 
 sc/source/ui/undo/undocell.cxx                                    |    5 
 sc/source/ui/unoobj/TablePivotCharts.cxx                          |    4 
 sc/source/ui/unoobj/chartuno.cxx                                  |    4 
 sc/source/ui/view/drawview.cxx                                    |    8 
 sc/source/ui/view/notemark.cxx                                    |    3 
 sc/source/ui/view/tabvwsh2.cxx                                    |    4 
 sc/source/ui/view/tabvwshb.cxx                                    |    4 
 sc/source/ui/view/tabvwshg.cxx                                    |    6 
 sc/source/ui/view/viewfun5.cxx                                    |    4 
 sc/source/ui/view/viewfun7.cxx                                    |   14 
 sd/inc/CustomAnimationEffect.hxx                                  |    3 
 sd/inc/Outliner.hxx                                               |    2 
 sd/inc/OutlinerIterator.hxx                                       |    4 
 sd/inc/sdpage.hxx                                                 |   10 
 sd/inc/undo/undoobjects.hxx                                       |   16 
 sd/qa/unit/tiledrendering/tiledrendering.cxx                      |    3 
 sd/source/core/CustomAnimationEffect.cxx                          |    4 
 sd/source/core/sdpage.cxx                                         |   79 -
 sd/source/core/sdpage2.cxx                                        |    1 
 sd/source/core/undo/undoobjects.cxx                               |   98 +-
 sd/source/filter/pdf/sdpdffilter.cxx                              |    6 
 sd/source/filter/ppt/pptin.cxx                                    |   40 
 sd/source/filter/ppt/pptin.hxx                                    |    2 
 sd/source/ui/animations/motionpathtag.cxx                         |   36 
 sd/source/ui/animations/motionpathtag.hxx                         |    4 
 sd/source/ui/dlg/animobjs.cxx                                     |   38 
 sd/source/ui/func/fucon3d.cxx                                     |   30 
 sd/source/ui/func/fuconarc.cxx                                    |    8 
 sd/source/ui/func/fuconbez.cxx                                    |    4 
 sd/source/ui/func/fuconcs.cxx                                     |    8 
 sd/source/ui/func/fuconrec.cxx                                    |   16 
 sd/source/ui/func/fuconuno.cxx                                    |    4 
 sd/source/ui/func/fuinsert.cxx                                    |   16 
 sd/source/ui/func/fuinsfil.cxx                                    |    4 
 sd/source/ui/func/fulinend.cxx                                    |    4 
 sd/source/ui/func/fumorph.cxx                                     |   22 
 sd/source/ui/func/fupoor.cxx                                      |    2 
 sd/source/ui/func/futext.cxx                                      |  106 +-
 sd/source/ui/func/fuvect.cxx                                      |    4 
 sd/source/ui/inc/OutlinerIteratorImpl.hxx                         |    4 
 sd/source/ui/inc/fucon3d.hxx                                      |    4 
 sd/source/ui/inc/fuconarc.hxx                                     |    2 
 sd/source/ui/inc/fuconbez.hxx                                     |    2 
 sd/source/ui/inc/fuconcs.hxx                                      |    2 
 sd/source/ui/inc/fuconrec.hxx                                     |    2 
 sd/source/ui/inc/fuconuno.hxx                                     |    2 
 sd/source/ui/inc/fupoor.hxx                                       |    2 
 sd/source/ui/inc/futext.hxx                                       |    8 
 sd/source/ui/inc/unopage.hxx                                      |    2 
 sd/source/ui/table/tablefunction.cxx                              |   16 
 sd/source/ui/unoidl/unoobj.cxx                                    |    4 
 sd/source/ui/unoidl/unopage.cxx                                   |    9 
 sd/source/ui/view/DocumentRenderer.cxx                            |   10 
 sd/source/ui/view/GraphicObjectBar.cxx                            |    4 
 sd/source/ui/view/Outliner.cxx                                    |   10 
 sd/source/ui/view/OutlinerIterator.cxx                            |   45 -
 sd/source/ui/view/drviews2.cxx                                    |   18 
 sd/source/ui/view/drviews6.cxx                                    |    5 
 sd/source/ui/view/drviews8.cxx                                    |    4 
 sd/source/ui/view/drviews9.cxx                                    |    8 
 sd/source/ui/view/drviewsa.cxx                                    |    1 
 sd/source/ui/view/drviewse.cxx                                    |   18 
 sd/source/ui/view/sdview.cxx                                      |   21 
 sd/source/ui/view/sdview2.cxx                                     |    4 
 sd/source/ui/view/sdview3.cxx                                     |   31 
 sd/source/ui/view/sdview4.cxx                                     |   36 
 sd/source/ui/view/viewoverlaymanager.cxx                          |   15 
 sfx2/source/doc/sfxbasemodel.cxx                                  |    6 
 svx/inc/extrud3d.hxx                                              |    4 
 svx/inc/polygn3d.hxx                                              |    5 
 svx/inc/sdr/primitive2d/sdrolecontentprimitive2d.hxx              |    4 
 svx/qa/unit/customshapes.cxx                                      |   20 
 svx/qa/unit/svdraw.cxx                                            |    7 
 svx/source/core/extedit.cxx                                       |   10 
 svx/source/customshapes/EnhancedCustomShape2d.cxx                 |   64 -
 svx/source/customshapes/EnhancedCustomShape3d.cxx                 |   33 
 svx/source/customshapes/EnhancedCustomShape3d.hxx                 |    4 
 svx/source/customshapes/EnhancedCustomShapeEngine.cxx             |   60 -
 svx/source/customshapes/EnhancedCustomShapeFontWork.cxx           |    8 
 svx/source/customshapes/EnhancedCustomShapeFontWork.hxx           |    3 
 svx/source/dialog/compressgraphicdialog.cxx                       |    4 
 svx/source/dialog/connctrl.cxx                                    |   19 
 svx/source/dialog/contwnd.cxx                                     |    4 
 svx/source/dialog/dlgctl3d.cxx                                    |   36 
 svx/source/dialog/dlgctrl.cxx                                     |   33 
 svx/source/dialog/imapwnd.cxx                                     |   21 
 svx/source/dialog/imapwnd.hxx                                     |    2 
 svx/source/dialog/measctrl.cxx                                    |    2 
 svx/source/engine3d/cube3d.cxx                                    |    4 
 svx/source/engine3d/extrud3d.cxx                                  |    8 
 svx/source/engine3d/float3d.cxx                                   |    1 
 svx/source/engine3d/lathe3d.cxx                                   |   10 
 svx/source/engine3d/obj3d.cxx                                     |    6 
 svx/source/engine3d/objfac3d.cxx                                  |    2 
 svx/source/engine3d/polygn3d.cxx                                  |    5 
 svx/source/engine3d/scene3d.cxx                                   |   11 
 svx/source/engine3d/sphere3d.cxx                                  |    4 
 svx/source/engine3d/view3d.cxx                                    |   53 -
 svx/source/engine3d/view3d1.cxx                                   |    6 
 svx/source/form/fmdmod.cxx                                        |    4 
 svx/source/form/fmdpage.cxx                                       |    2 
 svx/source/form/fmobj.cxx                                         |    2 
 svx/source/form/fmobjfac.cxx                                      |    6 
 svx/source/form/fmpage.cxx                                        |    6 
 svx/source/form/fmview.cxx                                        |   10 
 svx/source/form/fmvwimp.cxx                                       |   58 -
 svx/source/gallery2/galtheme.cxx                                  |    4 
 svx/source/inc/fmobj.hxx                                          |    2 
 svx/source/inc/fmvwimp.hxx                                        |   12 
 svx/source/inc/svdpdf.hxx                                         |    2 
 svx/source/sdr/contact/viewcontactofgraphic.cxx                   |    6 
 svx/source/sdr/primitive2d/sdrolecontentprimitive2d.cxx           |   10 
 svx/source/svdraw/selectioncontroller.cxx                         |    3 
 svx/source/svdraw/svdcrtv.cxx                                     |   43 -
 svx/source/svdraw/svddrgmt.cxx                                    |    6 
 svx/source/svdraw/svdedtv.cxx                                     |   28 
 svx/source/svdraw/svdedtv2.cxx                                    |   98 --
 svx/source/svdraw/svdedxv.cxx                                     |  127 +--
 svx/source/svdraw/svdetc.cxx                                      |    2 
 svx/source/svdraw/svdfmtf.cxx                                     |  178 ++--
 svx/source/svdraw/svdfmtf.hxx                                     |    2 
 svx/source/svdraw/svdmodel.cxx                                    |   16 
 svx/source/svdraw/svdoashp.cxx                                    |   19 
 svx/source/svdraw/svdobj.cxx                                      |  167 +--
 svx/source/svdraw/svdocapt.cxx                                    |   22 
 svx/source/svdraw/svdocirc.cxx                                    |    6 
 svx/source/svdraw/svdoedge.cxx                                    |   12 
 svx/source/svdraw/svdograf.cxx                                    |   40 
 svx/source/svdraw/svdogrp.cxx                                     |   10 
 svx/source/svdraw/svdomeas.cxx                                    |   20 
 svx/source/svdraw/svdomedia.cxx                                   |    2 
 svx/source/svdraw/svdoole2.cxx                                    |   22 
 svx/source/svdraw/svdopage.cxx                                    |    2 
 svx/source/svdraw/svdopath.cxx                                    |   14 
 svx/source/svdraw/svdorect.cxx                                    |    6 
 svx/source/svdraw/svdotext.cxx                                    |   12 
 svx/source/svdraw/svdotxln.cxx                                    |    4 
 svx/source/svdraw/svdotxtr.cxx                                    |   41 
 svx/source/svdraw/svdouno.cxx                                     |    2 
 svx/source/svdraw/svdoutl.cxx                                     |   12 
 svx/source/svdraw/svdovirt.cxx                                    |  146 +--
 svx/source/svdraw/svdpage.cxx                                     |   65 -
 svx/source/svdraw/svdpdf.cxx                                      |   57 -
 svx/source/svdraw/svdpoev.cxx                                     |   11 
 svx/source/svdraw/svdundo.cxx                                     |  303 
++-----
 svx/source/svdraw/svdxcgv.cxx                                     |   26 
 svx/source/table/svdotable.cxx                                    |   12 
 svx/source/table/tablecontroller.cxx                              |  101 +-
 svx/source/table/tableundo.cxx                                    |   24 
 svx/source/table/tableundo.hxx                                    |    4 
 svx/source/tbxctrls/fontworkgallery.cxx                           |   12 
 svx/source/unodraw/UnoGraphicExporter.cxx                         |    9 
 svx/source/unodraw/gluepts.cxx                                    |   79 +
 svx/source/unodraw/unopage.cxx                                    |   51 -
 svx/source/unodraw/unoshap2.cxx                                   |    9 
 svx/source/unodraw/unoshap3.cxx                                   |   23 
 svx/source/unodraw/unoshape.cxx                                   |  184 +---
 sw/inc/anchoredobject.hxx                                         |    9 
 sw/inc/dcontact.hxx                                               |   14 
 sw/inc/dobjfac.hxx                                                |    2 
 sw/inc/dpage.hxx                                                  |    2 
 sw/inc/unodraw.hxx                                                |    2 
 sw/source/core/doc/doclay.cxx                                     |   16 
 sw/source/core/draw/dcontact.cxx                                  |   70 -
 sw/source/core/draw/dflyobj.cxx                                   |    7 
 sw/source/core/draw/dobjfac.cxx                                   |    2 
 sw/source/core/draw/dpage.cxx                                     |    2 
 sw/source/core/draw/drawdoc.cxx                                   |   22 
 sw/source/core/frmedt/fecopy.cxx                                  |   19 
 sw/source/core/frmedt/feshview.cxx                                |   19 
 sw/source/core/inc/dflyobj.hxx                                    |    2 
 sw/source/core/layout/anchoredobject.cxx                          |    1 
 sw/source/core/layout/fly.cxx                                     |   11 
 sw/source/core/unocore/unodraw.cxx                                |   14 
 sw/source/filter/html/htmldrawreader.cxx                          |   10 
 sw/source/filter/html/htmltab.cxx                                 |    2 
 sw/source/filter/html/swhtml.cxx                                  |    1 
 sw/source/filter/html/swhtml.hxx                                  |    2 
 sw/source/filter/ww8/docxsdrexport.cxx                            |    9 
 sw/source/filter/ww8/wrtww8gr.cxx                                 |    6 
 sw/source/filter/ww8/ww8graf.cxx                                  |  131 +--
 sw/source/filter/ww8/ww8graf2.cxx                                 |   18 
 sw/source/filter/ww8/ww8par.cxx                                   |   25 
 sw/source/filter/ww8/ww8par.hxx                                   |   28 
 sw/source/filter/ww8/ww8par4.cxx                                  |   10 
 sw/source/filter/xml/swxml.cxx                                    |    5 
 sw/source/uibase/dochdl/swdtflvr.cxx                              |    8 
 sw/source/uibase/shells/drawsh.cxx                                |    6 
 sw/source/uibase/shells/grfshex.cxx                               |    2 
 sw/source/uibase/uiview/viewdraw.cxx                              |    4 
 314 files changed, 2512 insertions(+), 3376 deletions(-)

New commits:
commit 8611f6e259b807b4f19c8dc0eab86ca648891ce3
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Thu May 27 10:27:46 2021 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Mon Aug 29 13:44:02 2022 +0200

    ref-count SdrObject
    
    Which means we can get rid of the majestic hack of ScCaptionPtr
    Previously, SdrObject was manually managed, and the ownership
    passed around in very complicated fashion.
    
    Notes:
    
    (*) SvxShape has a strong reference to SdrObject, where
    previously it had a weak reference. It is now strong
    since otherwise the SdrObject will go away very eagerly.
    
    (*) SdrObject still has a weak reference to SvxShape
    
    (*) In the existing places that an SdrObject is being
    deleted, we now just clear the reference
    
    (*) instead of SwVirtFlyDrawObj removing itself from the
    page that contains inside it's destructor, make the call site
    do the removing from the page.
    
    (*) Needed to take the SolarMutex in UndoManagerHelper_Impl::impl_clear
    because this can be called from UNO (e.g. sfx2_complex JUnit test)
    and the SdrObjects need the SolarMutex when destructing.
    
    (*) handle a tricky situation with SwDrawVirtObj in the SwDrawModel
    destructor because the existing code wants mpDrawObj in
    SwAnchoredObject to be sometimes owning, sometimes not, which
    results in a cycle with the new code.
    
    Change-Id: I4d79df1660e386388e5d51030653755bca02a163
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138837
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/basctl/source/dlged/dlged.cxx b/basctl/source/dlged/dlged.cxx
index d0ac5611566c..306555489df5 100644
--- a/basctl/source/dlged/dlged.cxx
+++ b/basctl/source/dlged/dlged.cxx
@@ -342,8 +342,8 @@ void DlgEditor::SetDialog( const uno::Reference< 
container::XNameContainer >& xU
     pDlgEdForm = new DlgEdForm(*pDlgEdModel, *this);
     uno::Reference< awt::XControlModel > xDlgMod( m_xUnoControlDialogModel , 
uno::UNO_QUERY );
     pDlgEdForm->SetUnoControlModel(xDlgMod);
-    static_cast<DlgEdPage*>(pDlgEdModel->GetPage(0))->SetDlgEdForm( pDlgEdForm 
);
-    pDlgEdModel->GetPage(0)->InsertObject( pDlgEdForm );
+    static_cast<DlgEdPage*>(pDlgEdModel->GetPage(0))->SetDlgEdForm( 
pDlgEdForm.get() );
+    pDlgEdModel->GetPage(0)->InsertObject( pDlgEdForm.get() );
     AdjustPageSize();
     pDlgEdForm->SetRectFromProps();
     pDlgEdForm->UpdateTabIndices();     // for backward compatibility
@@ -382,11 +382,11 @@ void DlgEditor::SetDialog( const uno::Reference< 
container::XNameContainer >& xU
             Any aCtrl = m_xUnoControlDialogModel->getByName( 
indexToName.second );
             Reference< css::awt::XControlModel > xCtrlModel;
             aCtrl >>= xCtrlModel;
-            DlgEdObj* pCtrlObj = new DlgEdObj(*pDlgEdModel);
+            rtl::Reference<DlgEdObj> pCtrlObj = new DlgEdObj(*pDlgEdModel);
             pCtrlObj->SetUnoControlModel( xCtrlModel );
-            pCtrlObj->SetDlgEdForm( pDlgEdForm );
-            pDlgEdForm->AddChild( pCtrlObj );
-            pDlgEdModel->GetPage(0)->InsertObject( pCtrlObj );
+            pCtrlObj->SetDlgEdForm( pDlgEdForm.get() );
+            pDlgEdForm->AddChild( pCtrlObj.get() );
+            pDlgEdModel->GetPage(0)->InsertObject( pCtrlObj.get() );
             pCtrlObj->SetRectFromProps();
             pCtrlObj->UpdateStep();
             pCtrlObj->StartListening();
@@ -400,7 +400,7 @@ void DlgEditor::SetDialog( const uno::Reference< 
container::XNameContainer >& xU
 
 void DlgEditor::ResetDialog ()
 {
-    DlgEdForm* pOldDlgEdForm = pDlgEdForm;
+    DlgEdForm* pOldDlgEdForm = pDlgEdForm.get();
     DlgEdPage* pPage = static_cast<DlgEdPage*>(pDlgEdModel->GetPage(0));
     SdrPageView* pPgView = pDlgEdView->GetSdrPageView();
     bool bWasMarked = pDlgEdView->IsObjMarked( pOldDlgEdForm );
@@ -412,7 +412,7 @@ void DlgEditor::ResetDialog ()
     pPage->SetDlgEdForm( nullptr );
     SetDialog( m_xUnoControlDialogModel );
     if( bWasMarked )
-        pDlgEdView->MarkObj( pDlgEdForm, pPgView );
+        pDlgEdView->MarkObj( pDlgEdForm.get(), pPgView );
 }
 
 
@@ -603,12 +603,12 @@ void DlgEditor::SetInsertObj(SdrObjKind eObj)
 void DlgEditor::CreateDefaultObject()
 {
     // create object by factory
-    SdrObject* pObj = SdrObjFactory::MakeNewObject(
+    rtl::Reference<SdrObject> pObj = SdrObjFactory::MakeNewObject(
         *pDlgEdModel,
         pDlgEdView->GetCurrentObjInventor(),
         pDlgEdView->GetCurrentObjIdentifier());
 
-    DlgEdObj* pDlgEdObj = dynamic_cast<DlgEdObj*>(pObj);
+    DlgEdObj* pDlgEdObj = dynamic_cast<DlgEdObj*>(pObj.get());
     if (!pDlgEdObj)
         return;
 
@@ -914,9 +914,9 @@ void DlgEditor::Paste()
         Reference< util::XCloneable > xClone( xCM, uno::UNO_QUERY );
         Reference< awt::XControlModel > xCtrlModel( xClone->createClone(), 
uno::UNO_QUERY );
 
-        DlgEdObj* pCtrlObj = new DlgEdObj(*pDlgEdModel);
-        pCtrlObj->SetDlgEdForm(pDlgEdForm);         // set parent form
-        pDlgEdForm->AddChild(pCtrlObj);             // add child to parent form
+        rtl::Reference<DlgEdObj> pCtrlObj = new DlgEdObj(*pDlgEdModel);
+        pCtrlObj->SetDlgEdForm(pDlgEdForm.get());         // set parent form
+        pDlgEdForm->AddChild(pCtrlObj.get());             // add child to 
parent form
         pCtrlObj->SetUnoControlModel( xCtrlModel ); // set control model
 
         // set new name
@@ -950,7 +950,7 @@ void DlgEditor::Paste()
         m_xUnoControlDialogModel->insertByName( aOUniqueName , aCtrlModel );
 
         // insert object into drawing page
-        pDlgEdModel->GetPage(0)->InsertObject( pCtrlObj );
+        pDlgEdModel->GetPage(0)->InsertObject( pCtrlObj.get() );
         pCtrlObj->SetRectFromProps();
         pCtrlObj->UpdateStep();
         pDlgEdForm->UpdateTabOrderAndGroups();
@@ -958,7 +958,7 @@ void DlgEditor::Paste()
 
         // mark object
         SdrPageView* pPgView = pDlgEdView->GetSdrPageView();
-        pDlgEdView->MarkObj( pCtrlObj, pPgView, false, true);
+        pDlgEdView->MarkObj( pCtrlObj.get(), pPgView, false, true);
     }
 
     // center marked objects in dialog editor form
diff --git a/basctl/source/dlged/dlgedfac.cxx b/basctl/source/dlged/dlgedfac.cxx
index 03713c2b94ee..eed140560534 100644
--- a/basctl/source/dlged/dlgedfac.cxx
+++ b/basctl/source/dlged/dlgedfac.cxx
@@ -45,7 +45,7 @@ DlgEdFactory::~DlgEdFactory() COVERITY_NOEXCEPT_FALSE
 }
 
 
-IMPL_LINK( DlgEdFactory, MakeObject, SdrObjCreatorParams, aParams, SdrObject* )
+IMPL_LINK( DlgEdFactory, MakeObject, SdrObjCreatorParams, aParams, 
rtl::Reference<SdrObject> )
 {
     static const uno::Reference<lang::XMultiServiceFactory> xDialogSFact = [] {
         uno::Reference<lang::XMultiServiceFactory> xFact;
@@ -59,7 +59,7 @@ IMPL_LINK( DlgEdFactory, MakeObject, SdrObjCreatorParams, 
aParams, SdrObject* )
         return xFact;
     }();
 
-    SdrObject* pNewObj = nullptr;
+    rtl::Reference<SdrObject> pNewObj;
     if( (aParams.nInventor == SdrInventor::BasicDialog) &&
         (aParams.nObjIdentifier >= SdrObjKind::BasicDialogPushButton) &&
         (aParams.nObjIdentifier <= 
SdrObjKind::BasicDialogFormHorizontalScroll)    )
@@ -74,26 +74,26 @@ IMPL_LINK( DlgEdFactory, MakeObject, SdrObjCreatorParams, 
aParams, SdrObject* )
                  break;
             case SdrObjKind::BasicDialogFormRadio:
                  pNewObj = new DlgEdObj(aParams.rSdrModel, 
"com.sun.star.form.component.RadioButton", xDialogSFact );
-                 static_cast< DlgEdObj* >( pNewObj )->MakeDataAware( mxModel );
+                 static_cast< DlgEdObj* >( pNewObj.get() )->MakeDataAware( 
mxModel );
                  break;
             case SdrObjKind::BasicDialogCheckbox:
                  pNewObj = new DlgEdObj(aParams.rSdrModel, 
"com.sun.star.awt.UnoControlCheckBoxModel", xDialogSFact );
                  break;
             case SdrObjKind::BasicDialogFormCheck:
                  pNewObj = new DlgEdObj(aParams.rSdrModel, 
"com.sun.star.form.component.CheckBox", xDialogSFact );
-                 static_cast< DlgEdObj* >( pNewObj )->MakeDataAware( mxModel );
+                 static_cast< DlgEdObj* >( pNewObj.get() )->MakeDataAware( 
mxModel );
                  break;
             case SdrObjKind::BasicDialogListbox:
                  pNewObj = new DlgEdObj(aParams.rSdrModel, 
"com.sun.star.awt.UnoControlListBoxModel", xDialogSFact );
                  break;
             case SdrObjKind::BasicDialogFormList:
                  pNewObj = new DlgEdObj(aParams.rSdrModel, 
"com.sun.star.form.component.ListBox", xDialogSFact );
-                 static_cast< DlgEdObj* >( pNewObj )->MakeDataAware( mxModel );
+                 static_cast< DlgEdObj* >( pNewObj.get() )->MakeDataAware( 
mxModel );
                  break;
             case SdrObjKind::BasicDialogFormCombo:
             case SdrObjKind::BasicDialogCombobox:
             {
-                 DlgEdObj* pNew = nullptr;
+                 rtl::Reference<DlgEdObj> pNew;
                  if ( aParams.nObjIdentifier == 
SdrObjKind::BasicDialogCombobox )
                      pNew = new DlgEdObj(aParams.rSdrModel, 
"com.sun.star.awt.UnoControlComboBoxModel", xDialogSFact );
                  else
@@ -135,12 +135,12 @@ IMPL_LINK( DlgEdFactory, MakeObject, SdrObjCreatorParams, 
aParams, SdrObject* )
                  break;
             case SdrObjKind::BasicDialogFormHorizontalScroll:
                  pNewObj = new DlgEdObj(aParams.rSdrModel, 
"com.sun.star.form.component.ScrollBar", xDialogSFact );
-                 static_cast< DlgEdObj* >( pNewObj )->MakeDataAware( mxModel );
+                 static_cast< DlgEdObj* >( pNewObj.get() )->MakeDataAware( 
mxModel );
                  break;
             case SdrObjKind::BasicDialogFormVerticalScroll:
             case SdrObjKind::BasicDialogVerticalScrollbar:
             {
-                 DlgEdObj* pNew = nullptr;
+                 rtl::Reference<DlgEdObj> pNew;
                  if ( aParams.nObjIdentifier == 
SdrObjKind::BasicDialogVerticalScrollbar )
                      pNew = new DlgEdObj(aParams.rSdrModel, 
"com.sun.star.awt.UnoControlScrollBarModel", xDialogSFact );
                  else
@@ -167,7 +167,7 @@ IMPL_LINK( DlgEdFactory, MakeObject, SdrObjCreatorParams, 
aParams, SdrObject* )
                  break;
             case SdrObjKind::BasicDialogVerticalFixedLine:
             {
-                 DlgEdObj* pNew = new DlgEdObj(aParams.rSdrModel, 
"com.sun.star.awt.UnoControlFixedLineModel", xDialogSFact );
+                 rtl::Reference<DlgEdObj> pNew = new 
DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlFixedLineModel", 
xDialogSFact );
                  pNewObj = pNew;
                  // set vertical orientation
                  try
@@ -208,7 +208,7 @@ IMPL_LINK( DlgEdFactory, MakeObject, SdrObjCreatorParams, 
aParams, SdrObject* )
                  break;
             case SdrObjKind::BasicDialogFormSpin:
                  pNewObj = new DlgEdObj(aParams.rSdrModel, 
"com.sun.star.form.component.SpinButton", xDialogSFact );
-                 static_cast< DlgEdObj* >( pNewObj )->MakeDataAware( mxModel );
+                 static_cast< DlgEdObj* >( pNewObj.get() )->MakeDataAware( 
mxModel );
                  break;
             case SdrObjKind::BasicDialogTreeControl:
                  pNewObj = new DlgEdObj(aParams.rSdrModel, 
"com.sun.star.awt.tree.TreeControlModel", xDialogSFact );
diff --git a/basctl/source/dlged/dlgedobj.cxx b/basctl/source/dlged/dlgedobj.cxx
index 1d89210b7dd5..3e06307941da 100644
--- a/basctl/source/dlged/dlgedobj.cxx
+++ b/basctl/source/dlged/dlgedobj.cxx
@@ -70,7 +70,6 @@ DlgEditor& DlgEdObj::GetDialogEditor ()
 DlgEdObj::DlgEdObj(SdrModel& rSdrModel)
 :   SdrUnoObj(rSdrModel, OUString())
     ,bIsListening(false)
-    ,pDlgEdForm( nullptr )
 {
 }
 
@@ -118,7 +117,6 @@ DlgEdObj::DlgEdObj(
     const css::uno::Reference< css::lang::XMultiServiceFactory >& rxSFac)
 :   SdrUnoObj(rSdrModel, rModelName, rxSFac)
     ,bIsListening(false)
-    ,pDlgEdForm( nullptr )
 {
 }
 
@@ -906,16 +904,16 @@ SdrObjKind DlgEdObj::GetObjIdentifier() const
     }
 }
 
-DlgEdObj* DlgEdObj::CloneSdrObject(SdrModel& rTargetModel) const
+rtl::Reference<SdrObject> DlgEdObj::CloneSdrObject(SdrModel& rTargetModel) 
const
 {
     return new DlgEdObj(rTargetModel, *this);
 }
 
-SdrObjectUniquePtr DlgEdObj::getFullDragClone() const
+rtl::Reference<SdrObject> DlgEdObj::getFullDragClone() const
 {
     // no need to really add the clone for dragging, it's a temporary
     // object
-    return SdrObjectUniquePtr(new SdrUnoObj(getSdrModelFromSdrObject(), 
*this));
+    return rtl::Reference<SdrObject>(new SdrUnoObj(getSdrModelFromSdrObject(), 
*this));
 }
 
 void DlgEdObj::NbcMove( const Size& rSize )
@@ -961,7 +959,7 @@ bool DlgEdObj::EndCreate(SdrDragStat& rStat, SdrCreateCmd 
eCmd)
     // implementation. For historical reasons, the SdrPage (which is the 
DlgEdPage) was
     // already set. For now, get it from the SdrDragStat and use it to access 
and set
     // the local pDlgEdForm
-    if(nullptr == pDlgEdForm && nullptr != rStat.GetPageView())
+    if(!pDlgEdForm && nullptr != rStat.GetPageView())
     {
         const DlgEdPage* pDlgEdPage(dynamic_cast<const 
DlgEdPage*>(rStat.GetPageView()->GetPage()));
 
diff --git a/basctl/source/inc/dlged.hxx b/basctl/source/inc/dlged.hxx
index 0d1c461ad106..c50faf51b36c 100644
--- a/basctl/source/inc/dlged.hxx
+++ b/basctl/source/inc/dlged.hxx
@@ -112,7 +112,7 @@ private:
     std::unique_ptr<DlgEdModel> pDlgEdModel; // never nullptr
     DlgEdPage*          pDlgEdPage;  // never nullptr
     std::unique_ptr<DlgEdView> pDlgEdView; // never nullptr
-    DlgEdForm*          pDlgEdForm; // never nullptr
+    rtl::Reference<DlgEdForm>  pDlgEdForm; // never nullptr
     css::uno::Reference< css::container::XNameContainer >     
m_xUnoControlDialogModel;
     css::uno::Reference< css::awt::XControlContainer >        
m_xControlContainer;
     css::uno::Sequence< css::datatransfer::DataFlavor >       
m_ClipboardDataFlavors;
diff --git a/basctl/source/inc/dlgedfac.hxx b/basctl/source/inc/dlgedfac.hxx
index f200b01f84c9..5e583ada1729 100644
--- a/basctl/source/inc/dlgedfac.hxx
+++ b/basctl/source/inc/dlgedfac.hxx
@@ -35,7 +35,7 @@ public:
     DlgEdFactory(css::uno::Reference<css::frame::XModel> xModel);
     ~DlgEdFactory() COVERITY_NOEXCEPT_FALSE;
 
-    DECL_LINK(MakeObject, SdrObjCreatorParams, SdrObject*);
+    DECL_LINK(MakeObject, SdrObjCreatorParams, rtl::Reference<SdrObject>);
 };
 
 } // namespace basctl
diff --git a/basctl/source/inc/dlgedobj.hxx b/basctl/source/inc/dlgedobj.hxx
index d5e29cf48caf..a8c249adec16 100644
--- a/basctl/source/inc/dlgedobj.hxx
+++ b/basctl/source/inc/dlgedobj.hxx
@@ -50,7 +50,7 @@ class DlgEdObj: public SdrUnoObj
 
 private:
     bool            bIsListening;
-    DlgEdForm*      pDlgEdForm;
+    rtl::Reference<DlgEdForm> pDlgEdForm;
     css::uno::Reference< css::beans::XPropertyChangeListener> 
m_xPropertyChangeListener;
     css::uno::Reference< css::container::XContainerListener>  
m_xContainerListener;
 
@@ -94,15 +94,15 @@ protected:
 
 public:
     void SetDlgEdForm( DlgEdForm* pForm ) { pDlgEdForm = pForm; }
-    DlgEdForm* GetDlgEdForm() const { return pDlgEdForm; }
+    DlgEdForm* GetDlgEdForm() const { return pDlgEdForm.get(); }
 
     virtual SdrInventor GetObjInventor() const override;
     virtual SdrObjKind GetObjIdentifier() const override;
 
-    virtual DlgEdObj* CloneSdrObject(SdrModel& rTargetModel) const override;   
                                       // not working yet
+    virtual rtl::Reference<SdrObject> CloneSdrObject(SdrModel& rTargetModel) 
const override;                                          // not working yet
 
     // FullDrag support
-    virtual SdrObjectUniquePtr getFullDragClone() const override;
+    virtual rtl::Reference<SdrObject> getFullDragClone() const override;
 
     bool supportsService( OUString const & serviceName ) const;
     OUString GetDefaultName() const;
diff --git a/chart2/source/controller/dialogs/tp_3D_SceneIllumination.cxx 
b/chart2/source/controller/dialogs/tp_3D_SceneIllumination.cxx
index 4459219965d8..7cb38e9e8b48 100644
--- a/chart2/source/controller/dialogs/tp_3D_SceneIllumination.cxx
+++ b/chart2/source/controller/dialogs/tp_3D_SceneIllumination.cxx
@@ -30,6 +30,7 @@
 #include <svx/svx3ditems.hxx>
 #include <svx/svddef.hxx>
 #include <utility>
+#include <svx/obj3d.hxx>
 #include <vcl/svapp.hxx>
 #include <comphelper/diagnose_ex.hxx>
 
diff --git a/chart2/source/controller/drawinglayer/ViewElementListProvider.cxx 
b/chart2/source/controller/drawinglayer/ViewElementListProvider.cxx
index 1f0ef08578d3..0b3df1aa22ad 100644
--- a/chart2/source/controller/drawinglayer/ViewElementListProvider.cxx
+++ b/chart2/source/controller/drawinglayer/ViewElementListProvider.cxx
@@ -139,7 +139,7 @@ Graphic ViewElementListProvider::GetSymbolGraphic( 
sal_Int32 nStandardSymbol, co
         nStandardSymbol*=-1;
     if( o3tl::make_unsigned(nStandardSymbol) >= pSymbolList->GetObjCount() )
         nStandardSymbol %= pSymbolList->GetObjCount();
-    SdrObject* pObj = pSymbolList->GetObj(nStandardSymbol);
+    rtl::Reference<SdrObject> pObj = pSymbolList->GetObj(nStandardSymbol);
 
     ScopedVclPtrInstance< VirtualDevice > pVDev;
     pVDev->SetMapMode(MapMode(MapUnit::Map100thMM));
@@ -158,8 +158,8 @@ Graphic ViewElementListProvider::GetSymbolGraphic( 
sal_Int32 nStandardSymbol, co
     // directly clone to target SdrModel
     pObj = pObj->CloneSdrObject(*pModel);
 
-    pPage->NbcInsertObject(pObj);
-    aView.MarkObj(pObj,pPageView);
+    pPage->NbcInsertObject(pObj.get());
+    aView.MarkObj(pObj.get(),pPageView);
     if( pSymbolShapeProperties )
         pObj->SetMergedItemSet(*pSymbolShapeProperties);
 
@@ -172,7 +172,9 @@ Graphic ViewElementListProvider::GetSymbolGraphic( 
sal_Int32 nStandardSymbol, co
 
     aView.UnmarkAll();
     pObj=pPage->RemoveObject(0);
-    SdrObject::Free( pObj );
+    // these need to die before the associated SdrModel
+    pObj.clear();
+    pPage.clear();
 
     return aGraph;
 }
diff --git a/chart2/source/controller/main/ChartController_Tools.cxx 
b/chart2/source/controller/main/ChartController_Tools.cxx
index 18771a553eaa..085f31e8b574 100644
--- a/chart2/source/controller/main/ChartController_Tools.cxx
+++ b/chart2/source/controller/main/ChartController_Tools.cxx
@@ -418,7 +418,9 @@ void ChartController::impl_PasteShapes( SdrModel* pModel )
         {
             SdrObject* pObj(aIter.Next());
             // Clone to new SdrModel
-            SdrObject* pNewObj(pObj ? 
pObj->CloneSdrObject(pDrawModelWrapper->getSdrModel()) : nullptr);
+            rtl::Reference<SdrObject> pNewObj;
+            if (pObj)
+                pNewObj = 
pObj->CloneSdrObject(pDrawModelWrapper->getSdrModel());
 
             if ( pNewObj )
             {
@@ -429,7 +431,7 @@ void ChartController::impl_PasteShapes( SdrModel* pModel )
                     xShape->setPosition( awt::Point( 0, 0 ) );
                 }
 
-                pDestPage->InsertObject( pNewObj );
+                pDestPage->InsertObject( pNewObj.get() );
                 m_pDrawViewWrapper->AddUndo( 
std::make_unique<SdrUndoInsertObj>( *pNewObj ) );
                 xSelShape = xShape;
             }
diff --git a/chart2/source/controller/main/DrawCommandDispatch.cxx 
b/chart2/source/controller/main/DrawCommandDispatch.cxx
index c5cea4c5b6cd..9d896b75425e 100644
--- a/chart2/source/controller/main/DrawCommandDispatch.cxx
+++ b/chart2/source/controller/main/DrawCommandDispatch.cxx
@@ -362,11 +362,11 @@ void DrawCommandDispatch::execute( const OUString& 
rCommand, const Sequence< bea
     if ( eDrawMode != CHARTDRAW_INSERT )
         return;
 
-    SdrObject* pObj = createDefaultObject( nFeatureId );
+    rtl::Reference<SdrObject> pObj = createDefaultObject( nFeatureId );
     if ( pObj )
     {
         SdrPageView* pPageView = pDrawViewWrapper->GetSdrPageView();
-        if (pDrawViewWrapper->InsertObjectAtView(pObj, *pPageView))
+        if (pDrawViewWrapper->InsertObjectAtView(pObj.get(), *pPageView))
             
m_pChartController->SetAndApplySelection(Reference<drawing::XShape>(pObj->getUnoShape(),
 uno::UNO_QUERY));
         if ( nFeatureId == COMMAND_ID_DRAW_TEXT )
         {
@@ -402,9 +402,9 @@ void DrawCommandDispatch::setInsertObj(SdrObjKind eObj)
     }
 }
 
-SdrObject* DrawCommandDispatch::createDefaultObject( const sal_uInt16 nID )
+rtl::Reference<SdrObject> DrawCommandDispatch::createDefaultObject( const 
sal_uInt16 nID )
 {
-    SdrObject* pObj = nullptr;
+    rtl::Reference<SdrObject> pObj;
     DrawViewWrapper* pDrawViewWrapper = ( m_pChartController ? 
m_pChartController->GetDrawViewWrapper() : nullptr );
     DrawModelWrapper* pDrawModelWrapper = ( m_pChartController ? 
m_pChartController->GetDrawModelWrapper() : nullptr );
 
@@ -435,7 +435,7 @@ SdrObject* DrawCommandDispatch::createDefaultObject( const 
sal_uInt16 nID )
                     case COMMAND_ID_DRAW_LINE:
                     case COMMAND_ID_LINE_ARROW_END:
                         {
-                            if ( auto const pathObj = 
dynamic_cast<SdrPathObj*>( pObj) )
+                            if ( auto const pathObj = 
dynamic_cast<SdrPathObj*>( pObj.get()) )
                             {
                                 Point aStart = aRect.TopLeft();
                                 Point aEnd = aRect.BottomRight();
@@ -452,7 +452,7 @@ SdrObject* DrawCommandDispatch::createDefaultObject( const 
sal_uInt16 nID )
                         break;
                     case COMMAND_ID_DRAW_FREELINE_NOFILL:
                         {
-                            if ( auto const pathObj = 
dynamic_cast<SdrPathObj*>( pObj) )
+                            if ( auto const pathObj = 
dynamic_cast<SdrPathObj*>( pObj.get()) )
                             {
                                 basegfx::B2DPolygon aInnerPoly;
                                 aInnerPoly.append( basegfx::B2DPoint( 
aRect.Left(), aRect.Bottom() ) );
@@ -473,7 +473,7 @@ SdrObject* DrawCommandDispatch::createDefaultObject( const 
sal_uInt16 nID )
                     case COMMAND_ID_DRAW_TEXT:
                     case COMMAND_ID_DRAW_TEXT_VERTICAL:
                         {
-                            if ( SdrTextObj* pTextObj = 
dynamic_cast<SdrTextObj*>( pObj) )
+                            if ( SdrTextObj* pTextObj = 
dynamic_cast<SdrTextObj*>( pObj.get()) )
                             {
                                 pTextObj->SetLogicRect( aRect );
                                 bool bVertical = ( nID == 
COMMAND_ID_DRAW_TEXT_VERTICAL );
@@ -493,7 +493,7 @@ SdrObject* DrawCommandDispatch::createDefaultObject( const 
sal_uInt16 nID )
                     case COMMAND_ID_DRAW_CAPTION:
                     case COMMAND_ID_DRAW_CAPTION_VERTICAL:
                         {
-                            if ( SdrCaptionObj* pCaptionObj = 
dynamic_cast<SdrCaptionObj*>( pObj) )
+                            if ( SdrCaptionObj* pCaptionObj = 
dynamic_cast<SdrCaptionObj*>( pObj.get()) )
                             {
                                 bool bIsVertical( nID == 
COMMAND_ID_DRAW_CAPTION_VERTICAL );
                                 pCaptionObj->SetVerticalWriting( bIsVertical );
@@ -514,7 +514,7 @@ SdrObject* DrawCommandDispatch::createDefaultObject( const 
sal_uInt16 nID )
                         {
                             pObj->SetLogicRect( aRect );
                             SfxItemSet aSet( pDrawModelWrapper->GetItemPool() 
);
-                            setAttributes( pObj );
+                            setAttributes( pObj.get() );
                             pObj->SetMergedItemSet( aSet );
                         }
                         break;
diff --git a/chart2/source/controller/main/DrawCommandDispatch.hxx 
b/chart2/source/controller/main/DrawCommandDispatch.hxx
index febfa8338d40..6e707b102e68 100644
--- a/chart2/source/controller/main/DrawCommandDispatch.hxx
+++ b/chart2/source/controller/main/DrawCommandDispatch.hxx
@@ -20,6 +20,7 @@
 
 #include <svx/svdobjkind.hxx>
 #include "FeatureCommandDispatchBase.hxx"
+#include <rtl/ref.hxx>
 
 class SfxItemSet;
 class SdrObject;
@@ -60,7 +61,7 @@ protected:
 
 private:
     void setInsertObj(SdrObjKind eObj);
-    SdrObject* createDefaultObject( const sal_uInt16 nID );
+    rtl::Reference<SdrObject> createDefaultObject( const sal_uInt16 nID );
 
     bool parseCommandURL( const OUString& rCommandURL, sal_uInt16* 
pnFeatureId, OUString* pBaseCommand, OUString* pCustomShapeType );
 
diff --git a/chart2/source/view/main/ChartView.cxx 
b/chart2/source/view/main/ChartView.cxx
index 8faa295d2492..584dfdb5ea72 100644
--- a/chart2/source/view/main/ChartView.cxx
+++ b/chart2/source/view/main/ChartView.cxx
@@ -1310,8 +1310,7 @@ void lcl_removeEmptyGroupShapes( const SdrObject& rParent 
)
         if (pChildObjList->GetObjCount() == 0)
         {
             //remove empty group shape
-            SdrObject* pRemoved = pObjList->NbcRemoveObject(nIdx);
-            SdrObject::Free( pRemoved );
+            pObjList->NbcRemoveObject(nIdx);
         }
         else
             lcl_removeEmptyGroupShapes(*pChildSdrObject);
diff --git a/chart2/source/view/main/ShapeFactory.cxx 
b/chart2/source/view/main/ShapeFactory.cxx
index 4a3d207a1edb..d1f73636c546 100644
--- a/chart2/source/view/main/ShapeFactory.cxx
+++ b/chart2/source/view/main/ShapeFactory.cxx
@@ -1115,8 +1115,8 @@ rtl::Reference<SvxShapePolyPolygon>
         return nullptr;
 
     //create shape
-    SdrPathObj* pPath = new 
SdrPathObj(xTarget->GetSdrObject()->getSdrModelFromSdrObject(), 
SdrObjKind::Polygon);
-    xTarget->GetSdrObject()->GetSubList()->InsertObject(pPath);
+    rtl::Reference<SdrPathObj> pPath = new 
SdrPathObj(xTarget->GetSdrObject()->getSdrModelFromSdrObject(), 
SdrObjKind::Polygon);
+    xTarget->GetSdrObject()->GetSubList()->InsertObject(pPath.get());
 
     //set properties
     try
diff --git a/compilerplugins/clang/refcounting.cxx 
b/compilerplugins/clang/refcounting.cxx
index 61204b67a470..e65772f71e7d 100644
--- a/compilerplugins/clang/refcounting.cxx
+++ b/compilerplugins/clang/refcounting.cxx
@@ -505,6 +505,10 @@ bool RefCounting::VisitCXXDeleteExpr(const CXXDeleteExpr * 
cxxDeleteExpr)
         
compiler.getSourceManager().getSpellingLoc(cxxDeleteExpr->getBeginLoc()));
     if (loplugin::isSamePathname(aFileName, SRCDIR 
"/cppuhelper/source/weak.cxx"))
         return true;
+    if (loplugin::isSamePathname(aFileName, SRCDIR "/include/svx/svdobj.hxx"))
+        return true;
+    if (loplugin::isSamePathname(aFileName, SRCDIR 
"/svx/source/svdraw/svdobj.cxx"))
+        return true;
 
     if (!cxxDeleteExpr->getArgument())
         return true;
@@ -746,6 +750,15 @@ bool RefCounting::isCastingReference(const Expr* expr)
             if (callMethod->getReturnType()->isReferenceType())
                 return false;
     }
+    // Ignore
+    //     WeakReference x;
+    //     if (x.get.get())
+    // and similar stuff
+    if (auto memberCall2 = dyn_cast<CXXMemberCallExpr>(obj))
+    {
+        if 
(loplugin::TypeCheck(memberCall2->getImplicitObjectArgument()->getType()).Class("WeakReference"))
+                return false;
+    }
     return true;
 }
 
diff --git a/compilerplugins/clang/test/refcounting.cxx 
b/compilerplugins/clang/test/refcounting.cxx
index 7ab830fc913b..2b8ce94b42e6 100644
--- a/compilerplugins/clang/test/refcounting.cxx
+++ b/compilerplugins/clang/test/refcounting.cxx
@@ -13,16 +13,8 @@
 #include <rtl/ref.hxx>
 #include <boost/intrusive_ptr.hpp>
 #include <com/sun/star/uno/XInterface.hpp>
-
-namespace cppu
-{
-class OWeakObject
-{
-public:
-    void acquire();
-    void release();
-};
-}
+#include <cppuhelper/weak.hxx>
+#include <unotools/weakref.hxx>
 
 struct UnoObject : public cppu::OWeakObject
 {
@@ -115,6 +107,11 @@ void foo7()
     UnoSubObject* p3 = static_cast<UnoSubObject*>(getConstRef().get());
     (void)p3;
     p3 = static_cast<UnoSubObject*>(getConstRef().get());
+
+    // no warning expected, although, arguably, we should be assigning to a 
rtl::Reference temporary
+    unotools::WeakReference<UnoObject> weak1;
+    auto pTextObj = dynamic_cast<UnoSubObject*>(weak1.get().get());
+    (void)pTextObj;
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/compilerplugins/clang/weakobject.cxx 
b/compilerplugins/clang/weakobject.cxx
index d021dd419d89..7f1a2986faa5 100644
--- a/compilerplugins/clang/weakobject.cxx
+++ b/compilerplugins/clang/weakobject.cxx
@@ -1,3 +1,4 @@
+
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /*
  * This file is part of the LibreOffice project.
diff --git a/cui/source/tabpages/tpline.cxx b/cui/source/tabpages/tpline.cxx
index 04eaa41b92c9..85efe01a1c2f 100644
--- a/cui/source/tabpages/tpline.cxx
+++ b/cui/source/tabpages/tpline.cxx
@@ -828,7 +828,7 @@ void SvxLineTabPage::Reset( const SfxItemSet* rAttrs )
             if(m_pSymbolList->GetObjCount())
             {
                 nSymTmp %= m_pSymbolList->GetObjCount(); // Treat list as 
cyclic!
-                SdrObject *pObj=m_pSymbolList->GetObj(nSymTmp);
+                rtl::Reference<SdrObject> pObj=m_pSymbolList->GetObj(nSymTmp);
                 if(pObj)
                 {
                     // directly clone to target SdrModel
@@ -843,16 +843,16 @@ void SvxLineTabPage::Reset( const SfxItemSet* rAttrs )
                         pObj->SetMergedItemSet(m_rOutAttrs);
                     }
 
-                    pPage->NbcInsertObject(pObj);
+                    pPage->NbcInsertObject(pObj.get());
 
                     // Generate invisible square to give all symbol types a
                     // bitmap size, which is independent from specific glyph
-                    SdrObject* pInvisibleSquare(m_pSymbolList->GetObj(0));
+                    rtl::Reference<SdrObject> 
pInvisibleSquare(m_pSymbolList->GetObj(0));
 
                     // directly clone to target SdrModel
                     pInvisibleSquare = 
pInvisibleSquare->CloneSdrObject(*pModel);
 
-                    pPage->NbcInsertObject(pInvisibleSquare);
+                    pPage->NbcInsertObject(pInvisibleSquare.get());
                     
pInvisibleSquare->SetMergedItem(XFillTransparenceItem(100));
                     
pInvisibleSquare->SetMergedItem(XLineTransparenceItem(100));
 
@@ -868,10 +868,10 @@ void SvxLineTabPage::Reset( const SfxItemSet* rAttrs )
                     bIgnoreGraphic=true;
 
                     aView.UnmarkAll();
-                    pInvisibleSquare=pPage->RemoveObject(1);
-                    SdrObject::Free( pInvisibleSquare);
-                    pObj=pPage->RemoveObject(0);
-                    SdrObject::Free( pObj );
+                    pPage->RemoveObject(1);
+                    pInvisibleSquare.clear();
+                    pPage->RemoveObject(0);
+                    pObj.clear();
                 }
             }
         }
@@ -1455,25 +1455,25 @@ IMPL_LINK_NOARG(SvxLineTabPage, MenuCreateHdl_Impl, 
weld::Toggleable&, void)
 
         // Generate invisible square to give all symbols a
         // bitmap size, which is independent from specific glyph
-        SdrObject *pInvisibleSquare=m_pSymbolList->GetObj(0);
+        rtl::Reference<SdrObject> pInvisibleSquare=m_pSymbolList->GetObj(0);
 
         // directly clone to target SdrModel
         pInvisibleSquare = pInvisibleSquare->CloneSdrObject(*pModel);
 
-        pPage->NbcInsertObject(pInvisibleSquare);
+        pPage->NbcInsertObject(pInvisibleSquare.get());
         pInvisibleSquare->SetMergedItem(XFillTransparenceItem(100));
         pInvisibleSquare->SetMergedItem(XLineTransparenceItem(100));
 
         for(size_t i=0; i < m_pSymbolList->GetObjCount(); ++i)
         {
-            SdrObject *pObj=m_pSymbolList->GetObj(i);
+            rtl::Reference<SdrObject> pObj=m_pSymbolList->GetObj(i);
             assert(pObj);
 
             // directly clone to target SdrModel
             pObj = pObj->CloneSdrObject(*pModel);
 
             m_aGrfNames.emplace_back("");
-            pPage->NbcInsertObject(pObj);
+            pPage->NbcInsertObject(pObj.get());
             if(m_xSymbolAttr)
             {
                 pObj->SetMergedItemSet(*m_xSymbolAttr);
@@ -1486,8 +1486,8 @@ IMPL_LINK_NOARG(SvxLineTabPage, MenuCreateHdl_Impl, 
weld::Toggleable&, void)
             BitmapEx aBitmapEx(aView.GetMarkedObjBitmapEx());
             GDIMetaFile aMeta(aView.GetMarkedObjMetaFile());
             aView.UnmarkAll();
-            pObj=pPage->RemoveObject(1);
-            SdrObject::Free(pObj);
+            pPage->RemoveObject(1);
+            pObj.clear();
 
             SvxBmpItemInfo* pInfo = new SvxBmpItemInfo;
             pInfo->pBrushItem.reset(new SvxBrushItem(Graphic(aMeta), 
GPOS_AREA, SID_ATTR_BRUSH));
@@ -1507,8 +1507,8 @@ IMPL_LINK_NOARG(SvxLineTabPage, MenuCreateHdl_Impl, 
weld::Toggleable&, void)
             pVD->DrawBitmapEx(Point(), aBitmapEx);
             m_xSymbolsMenu->append(pInfo->sItemId, "", *pVD);
         }
-        pInvisibleSquare=pPage->RemoveObject(0);
-        SdrObject::Free(pInvisibleSquare);
+        pPage->RemoveObject(0);
+        pInvisibleSquare.clear();
 
         if (m_aGrfNames.empty())
             m_xSymbolMB->set_item_sensitive("symbols", false);
diff --git a/cui/source/tabpages/tplneend.cxx b/cui/source/tabpages/tplneend.cxx
index 951b27632c0b..fe7bc13158ea 100644
--- a/cui/source/tabpages/tplneend.cxx
+++ b/cui/source/tabpages/tplneend.cxx
@@ -109,7 +109,7 @@ void SvxLineEndDefTabPage::Construct()
     {
         SdrObjTransformInfoRec aInfoRec;
         pPolyObj->TakeObjInfo( aInfoRec );
-        SdrObjectUniquePtr pNewObj;
+        rtl::Reference<SdrObject> pNewObj;
         if( aInfoRec.bCanConvToPath )
             pNewObj = pPolyObj->ConvertToPolyObj( true, false );
 
@@ -341,7 +341,7 @@ IMPL_LINK_NOARG(SvxLineEndDefTabPage, ClickAddHdl_Impl, 
weld::Button&, void)
     if( pPolyObj )
     {
         const SdrObject* pNewObj;
-        SdrObjectUniquePtr pConvPolyObj;
+        rtl::Reference<SdrObject> pConvPolyObj;
 
         if( nullptr != dynamic_cast<const SdrPathObj*>( pPolyObj) )
         {
@@ -370,7 +370,7 @@ IMPL_LINK_NOARG(SvxLineEndDefTabPage, ClickAddHdl_Impl, 
weld::Button&, void)
         // normalize
         aNewPolyPolygon.transform(basegfx::utils::createTranslateB2DHomMatrix( 
-aNewRange.getMinX(), -aNewRange.getMinY()));
 
-        pConvPolyObj.reset();
+        pConvPolyObj.clear();
 
         OUString aNewName(SvxResId(RID_SVXSTR_LINEEND));
         OUString aDesc(CuiResId(RID_CUISTR_DESC_LINEEND));
diff --git a/filter/source/msfilter/escherex.cxx 
b/filter/source/msfilter/escherex.cxx
index 52326112d994..3044762de92a 100644
--- a/filter/source/msfilter/escherex.cxx
+++ b/filter/source/msfilter/escherex.cxx
@@ -4565,7 +4565,7 @@ sal_uInt32 EscherConnectorListEntry::GetConnectorRule( 
bool bFirst )
                 else if ( nGluePointType == 
drawing::EnhancedCustomShapeGluePointType::SEGMENTS )
                 {
                     tools::PolyPolygon aPolyPoly;
-                    SdrObjectUniquePtr 
pTemporaryConvertResultObject(pSdrObjCustomShape->DoConvertToPolyObj(true, 
true));
+                    rtl::Reference<SdrObject> 
pTemporaryConvertResultObject(pSdrObjCustomShape->DoConvertToPolyObj(true, 
true));
                     SdrPathObj* pSdrPathObj(dynamic_cast< SdrPathObj* 
>(pTemporaryConvertResultObject.get()));
 
                     if(pSdrPathObj)
@@ -4576,7 +4576,7 @@ sal_uInt32 EscherConnectorListEntry::GetConnectorRule( 
bool bFirst )
                     }
 
                     // do *not* forget to delete the temporary used SdrObject 
- possible memory leak (!)
-                    pTemporaryConvertResultObject.reset();
+                    pTemporaryConvertResultObject.clear();
                     pSdrPathObj = nullptr;
 
                     if(0 != aPolyPoly.Count())
diff --git a/filter/source/msfilter/msdffimp.cxx 
b/filter/source/msfilter/msdffimp.cxx
index 58032e65ee7b..3705429218bd 100644
--- a/filter/source/msfilter/msdffimp.cxx
+++ b/filter/source/msfilter/msdffimp.cxx
@@ -3819,9 +3819,9 @@ static void lcl_ApplyCropping( const DffPropSet& 
rPropSet, SfxItemSet* pSet, Gra
     }
 }
 
-SdrObject* SvxMSDffManager::ImportGraphic( SvStream& rSt, SfxItemSet& rSet, 
const DffObjData& rObjData )
+rtl::Reference<SdrObject> SvxMSDffManager::ImportGraphic( SvStream& rSt, 
SfxItemSet& rSet, const DffObjData& rObjData )
 {
-    SdrObject*  pRet = nullptr;
+    rtl::Reference<SdrObject> pRet;
     OUString    aLinkFileName;
     tools::Rectangle   aVisArea;
 
@@ -4018,7 +4018,7 @@ SdrObject* SvxMSDffManager::ImportGraphic( SvStream& rSt, 
SfxItemSet& rSet, cons
         {
             pRet = new SdrGrafObj(*pSdrModel);
             if( bGrfRead )
-                static_cast<SdrGrafObj*>(pRet)->SetGraphic( aGraf );
+                static_cast<SdrGrafObj*>(pRet.get())->SetGraphic( aGraf );
 
             if( bLinkGrf && !bGrfRead )     // sj: #i55484# if the graphic was 
embedded ( bGrfRead == true ) then
             {                               // we do not need to set a link. 
TODO: not to lose the information where the graphic is linked from
@@ -4057,7 +4057,7 @@ SdrObject* SvxMSDffManager::ImportGraphic( SvStream& rSt, 
SfxItemSet& rSet, cons
     }
     pRet->NbcSetLogicRect( rObjData.aBoundRect );
 
-    if (SdrGrafObj* pGrafObj = dynamic_cast<SdrGrafObj*>(pRet))
+    if (SdrGrafObj* pGrafObj = dynamic_cast<SdrGrafObj*>(pRet.get()))
     {
         if( aLinkFileName.getLength() )
         {
@@ -4077,10 +4077,10 @@ SdrObject* SvxMSDffManager::ImportGraphic( SvStream& 
rSt, SfxItemSet& rSet, cons
 }
 
 // PptSlidePersistEntry& rPersistEntry, SdPage* pPage
-SdrObject* SvxMSDffManager::ImportObj( SvStream& rSt, SvxMSDffClientData& 
rClientData,
+rtl::Reference<SdrObject> SvxMSDffManager::ImportObj( SvStream& rSt, 
SvxMSDffClientData& rClientData,
     tools::Rectangle& rClientRect, const tools::Rectangle& rGlobalChildRect, 
int nCalledByGroup, sal_Int32* pShapeId )
 {
-    SdrObject* pRet = nullptr;
+    rtl::Reference<SdrObject> pRet;
     DffRecordHeader aObjHd;
     bool bOk = ReadDffRecordHeader(rSt, aObjHd);
     if (bOk && aObjHd.nRecType == DFF_msofbtSpgrContainer)
@@ -4095,7 +4095,7 @@ SdrObject* SvxMSDffManager::ImportObj( SvStream& rSt, 
SvxMSDffClientData& rClien
     return pRet;
 }
 
-SdrObject* SvxMSDffManager::ImportGroup( const DffRecordHeader& rHd, SvStream& 
rSt, SvxMSDffClientData& rClientData,
+rtl::Reference<SdrObject> SvxMSDffManager::ImportGroup( const DffRecordHeader& 
rHd, SvStream& rSt, SvxMSDffClientData& rClientData,
                                             tools::Rectangle& rClientRect, 
const tools::Rectangle& rGlobalChildRect,
                                                 int nCalledByGroup, sal_Int32* 
pShapeId )
 {
@@ -4105,7 +4105,7 @@ SdrObject* SvxMSDffManager::ImportGroup( const 
DffRecordHeader& rHd, SvStream& r
     if (!rHd.SeekToContent(rSt))
         return nullptr;
 
-    SdrObjectUniquePtr xRet;
+    rtl::Reference<SdrObject> xRet;
 
     DffRecordHeader aRecHd;     // the first atom has to be the SpContainer 
for the GroupObject
     bool bOk = ReadDffRecordHeader(rSt, aRecHd);
@@ -4113,8 +4113,8 @@ SdrObject* SvxMSDffManager::ImportGroup( const 
DffRecordHeader& rHd, SvStream& r
     {
         mnFix16Angle = 0_deg100;
         if (!aRecHd.SeekToBegOfRecord(rSt))
-            return xRet.release();
-        xRet.reset(ImportObj(rSt, rClientData, rClientRect, rGlobalChildRect, 
nCalledByGroup + 1, pShapeId));
+            return xRet;
+        xRet = ImportObj(rSt, rClientData, rClientRect, rGlobalChildRect, 
nCalledByGroup + 1, pShapeId);
         if (xRet)
         {
             Degree100 nGroupRotateAngle(0);
@@ -4145,7 +4145,7 @@ SdrObject* SvxMSDffManager::ImportGroup( const 
DffRecordHeader& rHd, SvStream& r
 
             // now importing the inner objects of the group
             if (!aRecHd.SeekToEndOfRecord(rSt))
-                return xRet.release();
+                return xRet;
 
             while (rSt.good() && ( rSt.Tell() < rHd.GetRecEndFilePos()))
             {
@@ -4157,43 +4157,43 @@ SdrObject* SvxMSDffManager::ImportGroup( const 
DffRecordHeader& rHd, SvStream& r
                     tools::Rectangle aGroupClientAnchor, aGroupChildAnchor;
                     GetGroupAnchors( aRecHd2, rSt, aGroupClientAnchor, 
aGroupChildAnchor, aClientRect, aGlobalChildRect );
                     if (!aRecHd2.SeekToBegOfRecord(rSt))
-                        return xRet.release();
+                        return xRet;
                     sal_Int32 nShapeId;
-                    SdrObject* pTmp = ImportGroup( aRecHd2, rSt, rClientData, 
aGroupClientAnchor, aGroupChildAnchor, nCalledByGroup + 1, &nShapeId );
+                    rtl::Reference<SdrObject> pTmp = ImportGroup( aRecHd2, 
rSt, rClientData, aGroupClientAnchor, aGroupChildAnchor, nCalledByGroup + 1, 
&nShapeId );
                     if (pTmp)
                     {
                         SdrObjGroup* pGroup = 
dynamic_cast<SdrObjGroup*>(xRet.get());
                         if (pGroup && pGroup->GetSubList())
                         {
-                            pGroup->GetSubList()->NbcInsertObject(pTmp);
+                            pGroup->GetSubList()->NbcInsertObject(pTmp.get());
                             if (nShapeId)
-                                insertShapeId(nShapeId, pTmp);
+                                insertShapeId(nShapeId, pTmp.get());
                         }
                         else
-                            FreeObj(rClientData, pTmp);
+                            FreeObj(rClientData, pTmp.get());
                     }
                 }
                 else if ( aRecHd2.nRecType == DFF_msofbtSpContainer )
                 {
                     if (!aRecHd2.SeekToBegOfRecord(rSt))
-                        return xRet.release();
+                        return xRet;
                     sal_Int32 nShapeId;
-                    SdrObject* pTmp = ImportShape( aRecHd2, rSt, rClientData, 
aClientRect, aGlobalChildRect, nCalledByGroup + 1, &nShapeId );
+                    rtl::Reference<SdrObject> pTmp = ImportShape( aRecHd2, 
rSt, rClientData, aClientRect, aGlobalChildRect, nCalledByGroup + 1, &nShapeId 
);
                     if (pTmp)
                     {
                         SdrObjGroup* pGroup = 
dynamic_cast<SdrObjGroup*>(xRet.get());
                         if (pGroup && pGroup->GetSubList())
                         {
-                            pGroup->GetSubList()->NbcInsertObject(pTmp);
+                            pGroup->GetSubList()->NbcInsertObject(pTmp.get());
                             if (nShapeId)
-                                insertShapeId(nShapeId, pTmp);
+                                insertShapeId(nShapeId, pTmp.get());
                         }
                         else
-                            FreeObj(rClientData, pTmp);
+                            FreeObj(rClientData, pTmp.get());
                     }
                 }
                 if (!aRecHd2.SeekToEndOfRecord(rSt))
-                    return xRet.release();
+                    return xRet;
             }
 
             if ( nGroupRotateAngle )
@@ -4215,13 +4215,13 @@ SdrObject* SvxMSDffManager::ImportGroup( const 
DffRecordHeader& rHd, SvStream& r
     if (o3tl::make_unsigned(nCalledByGroup) < maPendingGroupData.size())
     {
         // finalization for this group is pending, do it now
-        xRet.reset(FinalizeObj(maPendingGroupData.back().first, 
xRet.release()));
+        xRet = FinalizeObj(maPendingGroupData.back().first, xRet.get());
         maPendingGroupData.pop_back();
     }
-    return xRet.release();
+    return xRet;
 }
 
-SdrObject* SvxMSDffManager::ImportShape( const DffRecordHeader& rHd, SvStream& 
rSt, SvxMSDffClientData& rClientData,
+rtl::Reference<SdrObject> SvxMSDffManager::ImportShape( const DffRecordHeader& 
rHd, SvStream& rSt, SvxMSDffClientData& rClientData,
                                             tools::Rectangle& rClientRect, 
const tools::Rectangle& rGlobalChildRect,
                                             int nCalledByGroup, sal_Int32* 
pShapeId )
 {
@@ -4335,7 +4335,7 @@ SdrObject* SvxMSDffManager::ImportShape( const 
DffRecordHeader& rHd, SvStream& r
     if ( aObjData.nSpFlags & ShapeFlag::Background )
         aObjData.aBoundRect = tools::Rectangle( Point(), Size( 1, 1 ) );
 
-    SdrObjectUniquePtr xRet;
+    rtl::Reference<SdrObject> xRet;
 
     tools::Rectangle aTextRect;
     if ( !aObjData.aBoundRect.IsEmpty() )
@@ -4361,7 +4361,7 @@ SdrObject* SvxMSDffManager::ImportShape( const 
DffRecordHeader& rHd, SvStream& r
 
         if ( aObjData.nSpFlags & ShapeFlag::Group )
         {
-            xRet.reset(new SdrObjGroup(*pSdrModel));
+            xRet = new SdrObjGroup(*pSdrModel);
             /*  After CWS aw033 has been integrated, an empty group object
                 cannot store its resulting bounding rectangle anymore. We have
                 to return this rectangle via rClientRect now, but only, if
@@ -4381,7 +4381,7 @@ SdrObject* SvxMSDffManager::ImportShape( const 
DffRecordHeader& rHd, SvStream& r
             if ( bGraphic )
             {
                 if (!mbSkipImages) {
-                    xRet.reset(ImportGraphic(rSt, aSet, aObjData));        // 
SJ: #68396# is no longer true (fixed in ppt2000)
+                    xRet = ImportGraphic(rSt, aSet, aObjData);        // SJ: 
#68396# is no longer true (fixed in ppt2000)
                     ApplyAttributes( rSt, aSet, aObjData );
                     xRet->SetMergedItemSet(aSet);
                 }
@@ -4391,10 +4391,10 @@ SdrObject* SvxMSDffManager::ImportShape( const 
DffRecordHeader& rHd, SvStream& r
                 basegfx::B2DPolygon aPoly;
                 aPoly.append(basegfx::B2DPoint(aObjData.aBoundRect.Left(), 
aObjData.aBoundRect.Top()));
                 aPoly.append(basegfx::B2DPoint(aObjData.aBoundRect.Right(), 
aObjData.aBoundRect.Bottom()));
-                xRet.reset(new SdrPathObj(
+                xRet = new SdrPathObj(
                     *pSdrModel,
                     SdrObjKind::Line,
-                    basegfx::B2DPolyPolygon(aPoly)));
+                    basegfx::B2DPolyPolygon(aPoly));
                 ApplyAttributes( rSt, aSet, aObjData );
                 xRet->SetMergedItemSet(aSet);
             }
@@ -4405,7 +4405,7 @@ SdrObject* SvxMSDffManager::ImportShape( const 
DffRecordHeader& rHd, SvStream& r
 
                     ApplyAttributes( rSt, aSet, aObjData );
 
-                    xRet.reset(new SdrObjCustomShape(*pSdrModel));
+                    xRet = new SdrObjCustomShape(*pSdrModel);
 
                     sal_uInt32 ngtextFStrikethrough = GetPropertyValue( 
DFF_Prop_gtextFStrikethrough, 0 );
                     bool bIsFontwork = ( ngtextFStrikethrough & 0x4000 ) != 0;
@@ -4797,7 +4797,7 @@ SdrObject* SvxMSDffManager::ImportShape( const 
DffRecordHeader& rHd, SvStream& r
                         }
                         basegfx::B2DPolyPolygon aPoly( 
static_cast<SdrObjCustomShape*>(xRet.get())->GetLineGeometry( true ) );
 
-                        xRet.reset(new SdrEdgeObj(*pSdrModel));
+                        xRet = new SdrEdgeObj(*pSdrModel);
                         ApplyAttributes( rSt, aSet, aObjData );
                         xRet->SetLogicRect( aObjData.aBoundRect );
                         xRet->SetMergedItemSet(aSet);
@@ -4914,7 +4914,7 @@ SdrObject* SvxMSDffManager::ImportShape( const 
DffRecordHeader& rHd, SvStream& r
             xRet->SetName(aObjName);
     }
 
-    xRet.reset(ProcessObj(rSt, aObjData, rClientData, aTextRect, 
xRet.release()));
+    xRet = ProcessObj(rSt, aObjData, rClientData, aTextRect, xRet.get());
 
     if (xRet)
     {
@@ -4950,9 +4950,9 @@ SdrObject* SvxMSDffManager::ImportShape( const 
DffRecordHeader& rHd, SvStream& r
     }
     else
     {
-        xRet.reset(FinalizeObj(aObjData, xRet.release()));
+        xRet = FinalizeObj(aObjData, xRet.get());
     }
-    return xRet.release();
+    return xRet;
 }
 
 tools::Rectangle SvxMSDffManager::GetGlobalChildAnchor( const DffRecordHeader& 
rHd, SvStream& rSt, tools::Rectangle& aClientRect )
@@ -5114,7 +5114,7 @@ void 
SvxMSDffImportData::insert(std::unique_ptr<SvxMSDffImportRec> pImpRec)
     if (bSuccess)
     {
         SvxMSDffImportRec* pRec = aRet.first->get();
-        m_ObjToRecMap[pRec->pObj] = pRec;
+        m_ObjToRecMap[pRec->pObj.get()] = pRec;
     }
 }
 
@@ -5143,16 +5143,16 @@ void SvxMSDffManager::NotifyFreeObj(SvxMSDffClientData& 
rData, SdrObject* pObj)
 void SvxMSDffManager::FreeObj(SvxMSDffClientData& rData, SdrObject* pObj)
 {
     NotifyFreeObj(rData, pObj);
-    SdrObject::Free(pObj);
 }
 
-SdrObject* SvxMSDffManager::ProcessObj(SvStream& rSt,
+rtl::Reference<SdrObject> SvxMSDffManager::ProcessObj(SvStream& rSt,
                                        DffObjData& rObjData,
                                        SvxMSDffClientData& rData,
                                        tools::Rectangle& rTextRect,
-                                       SdrObject* pObj
+                                       SdrObject* pObj1
                                        )
 {
+    rtl::Reference<SdrObject> pObj = pObj1;
     if( !rTextRect.IsEmpty() )
     {
         SvxMSDffImportData& rImportData = 
static_cast<SvxMSDffImportData&>(rData);
@@ -5229,8 +5229,8 @@ SdrObject* SvxMSDffManager::ProcessObj(SvStream& rSt,
         }
 
         //  text frame, also Title or Outline
-        SdrObject*  pOrgObj  = pObj;
-        SdrRectObj* pTextObj = nullptr;
+        rtl::Reference<SdrObject> pOrgObj  = pObj;
+        rtl::Reference<SdrRectObj> pTextObj;
         sal_uInt32 nTextId = GetPropertyValue( DFF_Prop_lTxid, 0 );
         if( nTextId )
         {
@@ -5259,8 +5259,8 @@ SdrObject* SvxMSDffManager::ProcessObj(SvStream& rSt,
 
             if (bTextFrame)
             {
-                SdrObject::Free( pObj );
-                pObj = pOrgObj = nullptr;
+                pObj = nullptr;
+                pOrgObj = nullptr;
             }
 
             // Distance of Textbox to its surrounding Customshape
@@ -5497,20 +5497,20 @@ SdrObject* SvxMSDffManager::ProcessObj(SvStream& rSt,
 
             if( !pObj )
             {
-                pObj = pTextObj;
+                pObj = pTextObj.get();
             }
             else
             {
-                if( pTextObj != pObj )
+                if( pTextObj.get() != pObj.get() )
                 {
-                    SdrObject* pGroup = new SdrObjGroup(*pSdrModel);
-                    pGroup->GetSubList()->NbcInsertObject( pObj );
-                    pGroup->GetSubList()->NbcInsertObject( pTextObj );
+                    rtl::Reference<SdrObject> pGroup = new 
SdrObjGroup(*pSdrModel);
+                    pGroup->GetSubList()->NbcInsertObject( pObj.get() );
+                    pGroup->GetSubList()->NbcInsertObject( pTextObj.get() );
                     if (pOrgObj == pObj)
                         pOrgObj = pGroup;
                     else
                         pOrgObj = pObj;
-                    pObj = pGroup;
+                    pObj = pGroup.get();
                 }
             }
         }
@@ -5623,7 +5623,7 @@ SdrObject* SvxMSDffManager::ProcessObj(SvStream& rSt,
             // amend the import record list
             if( pOrgObj )
             {
-                pImpRec->pObj = pOrgObj;
+                pImpRec->pObj = pOrgObj.get();
                 
rImportData.insert(std::unique_ptr<SvxMSDffImportRec>(pImpRec));
                 bDeleteImpRec = false;
                 if (pImpRec == pTextImpRec)
@@ -5634,7 +5634,7 @@ SdrObject* SvxMSDffManager::ProcessObj(SvStream& rSt,
             {
                 // Modify ShapeId (must be unique)
                 pImpRec->nShapeId |= 0x8000000;
-                pTextImpRec->pObj = pTextObj;
+                pTextImpRec->pObj = pTextObj.get();
                 
rImportData.insert(std::unique_ptr<SvxMSDffImportRec>(pTextImpRec));
                 bDeleteTextImpRec = false;
                 if (pTextImpRec == pImpRec)
@@ -5650,7 +5650,7 @@ SdrObject* SvxMSDffManager::ProcessObj(SvStream& rSt,
               )
                 StoreShapeOrder( pImpRec->nShapeId,
                                 ( 
static_cast<sal_uLong>(pImpRec->aTextId.nTxBxS) << 16 )
-                                    + pImpRec->aTextId.nSequence, pObj );
+                                    + pImpRec->aTextId.nSequence, pObj.get() );
         }
 
         if (bDeleteImpRec)
@@ -6354,7 +6354,7 @@ bool SvxMSDffManager::GetShapeContainerData( SvStream& 
rSt,
     Access to a shape at runtime (via the Shape-Id)
     ----------------------------
 ******************************************************************************/
-bool SvxMSDffManager::GetShape(sal_uLong nId, SdrObject*&         rpShape,
+bool SvxMSDffManager::GetShape(sal_uLong nId, rtl::Reference<SdrObject>& 
rpShape,
                                           SvxMSDffImportData& rData)
 {
     auto const pTmpRec = std::make_shared<SvxMSDffShapeInfo>(0, nId);
@@ -6384,7 +6384,7 @@ bool SvxMSDffManager::GetShape(sal_uLong nId, SdrObject*& 
        rpShape,
     rStCtrl.Seek( nOldPosCtrl );
     if( &rStCtrl != pStData && pStData )
         pStData->Seek( nOldPosData );
-    return ( nullptr != rpShape );
+    return bool( rpShape );
 }
 
 
@@ -6733,13 +6733,13 @@ bool SvxMSDffManager::ShapeHasText( sal_uLong /* 
nShapeId */, sal_uLong /* nFile
 }
 
 // #i32596# - add new parameter <_nCalledByGroup>
-SdrObject* SvxMSDffManager::ImportOLE( sal_uInt32 nOLEId,
+rtl::Reference<SdrObject> SvxMSDffManager::ImportOLE( sal_uInt32 nOLEId,
                                        const Graphic& rGrf,
                                        const tools::Rectangle& rBoundRect,
                                        const tools::Rectangle& rVisArea,
                                        const int /* _nCalledByGroup */ ) const
 {
-    SdrObject* pRet = nullptr;
+    rtl::Reference<SdrObject> pRet;
     OUString sStorageName;
     tools::SvRef<SotStorage> xSrcStg;
     ErrCode nError = ERRCODE_NONE;
@@ -7254,7 +7254,7 @@ css::uno::Reference < css::embed::XEmbeddedObject >  
SvxMSDffManager::CheckForCo
 }
 
 // TODO/MBA: code review and testing!
-SdrOle2Obj* SvxMSDffManager::CreateSdrOLEFromStorage(
+rtl::Reference<SdrOle2Obj> SvxMSDffManager::CreateSdrOLEFromStorage(
     SdrModel& rSdrModel,
     const OUString& rStorageName,
     tools::SvRef<SotStorage> const & rSrcStorage,
@@ -7269,7 +7269,7 @@ SdrOle2Obj* SvxMSDffManager::CreateSdrOLEFromStorage(
     OUString const& rBaseURL)
 {
     sal_Int64 nAspect = nRecommendedAspect;
-    SdrOle2Obj* pRet = nullptr;
+    rtl::Reference<SdrOle2Obj> pRet;
     if( rSrcStorage.is() && xDestStorage.is() && rStorageName.getLength() )
     {
         comphelper::EmbeddedObjectContainer aCnt( xDestStorage );
@@ -7476,8 +7476,7 @@ bool SvxMSDffManager::SetPropValue( const uno::Any& rAny, 
const uno::Reference<
 }
 
 SvxMSDffImportRec::SvxMSDffImportRec()
-    : pObj( nullptr ),
-      nClientAnchorLen(  0 ),
+    : nClientAnchorLen(  0 ),
       nClientDataLen(    0 ),
       nXAlign( 0 ), // position n cm from left
       nYAlign( 0 ), // position n cm below
diff --git a/filter/source/msfilter/svdfppt.cxx 
b/filter/source/msfilter/svdfppt.cxx
index d5ee7986b242..4511789b0586 100644
--- a/filter/source/msfilter/svdfppt.cxx
+++ b/filter/source/msfilter/svdfppt.cxx
@@ -494,7 +494,6 @@ PptSlidePersistEntry::PptSlidePersistEntry() :
     nSlidePersistEndOffset  ( 0 ),
     nBackgroundOffset       ( 0 ),
     nDrawingDgId            ( 0xffffffff ),
-    pBObj                   ( nullptr ),
     ePageKind               ( PPT_MASTERPAGE ),
     bNotesMaster            ( false ),
     bHandoutMaster          ( false ),
@@ -729,13 +728,13 @@ void ProcessData::NotifyFreeObj(SdrObject* pObj)
    The parameter pOriginalObj is the object as it was imported by our general 
escher import, it must either
    be deleted or it can be returned to be inserted into the sdr page.
 */
-SdrObject* SdrEscherImport::ProcessObj( SvStream& rSt, DffObjData& rObjData, 
SvxMSDffClientData& rClientData, tools::Rectangle& rTextRect, SdrObject* 
pOriginalObj )
+rtl::Reference<SdrObject> SdrEscherImport::ProcessObj( SvStream& rSt, 
DffObjData& rObjData, SvxMSDffClientData& rClientData, tools::Rectangle& 
rTextRect, SdrObject* pOriginalObj )
 {
     if ( dynamic_cast<const SdrObjCustomShape* >(pOriginalObj) !=  nullptr )
         pOriginalObj->SetMergedItem( SdrTextFixedCellHeightItem( true ) );
 
     // we are initializing our return value with the object that was imported 
by our escher import
-    SdrObject* pRet = pOriginalObj;
+    rtl::Reference<SdrObject> pRet = pOriginalObj;
 
     ProcessData& rData = static_cast<ProcessData&>(rClientData);
     PptSlidePersistEntry& rPersistEntry = rData.rPersistEntry;
@@ -780,7 +779,7 @@ SdrObject* SdrEscherImport::ProcessObj( SvStream& rSt, 
DffObjData& rObjData, Svx
 
                     case PPT_PST_RecolorInfoAtom :
                     {
-                        if ( auto pSdrGrafObj = dynamic_cast<SdrGrafObj* 
>(pRet) )
+                        if ( auto pSdrGrafObj = dynamic_cast<SdrGrafObj* 
>(pRet.get()) )
                             if ( pSdrGrafObj->HasGDIMetaFile() )
                             {
                                 Graphic aGraphic( pSdrGrafObj->GetGraphic() );
@@ -801,7 +800,6 @@ SdrObject* SdrEscherImport::ProcessObj( SvStream& rSt, 
DffObjData& rObjData, Svx
                 nPageNum--;
 
             // replacing the object which we will return with a SdrPageObj
-            SdrObject::Free( pRet );
             pRet = new SdrPageObj(
                 *pSdrModel,
                 rObjData.aBoundRect,
@@ -849,10 +847,12 @@ SdrObject* SdrEscherImport::ProcessObj( SvStream& rSt, 
DffObjData& rObjData, Svx
                 if ( pRet )
                 {
                     bool bDeleteSource = aTextObj.GetOEPlaceHolderAtom() != 
nullptr;
-                    if ( bDeleteSource  && dynamic_cast<const SdrGrafObj* 
>(pRet) ==  nullptr     // we are not allowed to get
-                            && dynamic_cast<const SdrObjGroup* >(pRet) ==  
nullptr                // grouped placeholder objects
-                                && dynamic_cast<const SdrOle2Obj* >(pRet) ==  
nullptr )
-                        SdrObject::Free( pRet );
+                    if ( bDeleteSource  && dynamic_cast<const SdrGrafObj* 
>(pRet.get()) ==  nullptr     // we are not allowed to get
+                            && dynamic_cast<const SdrObjGroup* >(pRet.get()) 
==  nullptr                // grouped placeholder objects
+                                && dynamic_cast<const SdrOle2Obj* 
>(pRet.get()) ==  nullptr )
+                    {
+                        pRet = nullptr;
+                    }
                 }
                 sal_uInt32 nTextFlags = aTextObj.GetTextFlags();
                 sal_Int32 nTextLeft = GetPropertyValue( DFF_Prop_dxTextLeft, 
25 * 3600 );   // 0.25 cm (emu)
@@ -1049,11 +1049,11 @@ SdrObject* SdrEscherImport::ProcessObj( SvStream& rSt, 
DffObjData& rObjData, Svx
                         eTextKind = SdrObjKind::Rectangle;
                     }
                 }
-                SdrObject* pTObj = nullptr;
+                rtl::Reference<SdrObject> pTObj;
                 bool bWordWrap = GetPropertyValue(DFF_Prop_WrapText, 
mso_wrapSquare) != mso_wrapNone;
                 bool bFitShapeToText = ( GetPropertyValue( 
DFF_Prop_FitTextToShape, 0 ) & 2 ) != 0;
 
-                if ( dynamic_cast<const SdrObjCustomShape* >(pRet) !=  nullptr 
&& ( eTextKind == SdrObjKind::Rectangle ) )
+                if ( dynamic_cast<const SdrObjCustomShape* >(pRet.get()) !=  
nullptr && ( eTextKind == SdrObjKind::Rectangle ) )
                 {
                     bAutoGrowHeight = bFitShapeToText;
                     bAutoGrowWidth = !bWordWrap;
@@ -1062,9 +1062,8 @@ SdrObject* SdrEscherImport::ProcessObj( SvStream& rSt, 
DffObjData& rObjData, Svx
                 }
                 else
                 {
-                    if ( dynamic_cast<const SdrObjCustomShape* >(pRet) !=  
nullptr )
+                    if ( dynamic_cast<const SdrObjCustomShape* >(pRet.get()) 
!=  nullptr )
                     {
-                        SdrObject::Free( pRet );
                         pRet = nullptr;
                     }
                     pTObj = new SdrRectObj(
@@ -1103,7 +1102,7 @@ SdrObject* SdrEscherImport::ProcessObj( SvStream& rSt, 
DffObjData& rObjData, Svx
                     pTObj->SetMergedItem( 
SdrTextFitToSizeTypeItem(drawing::TextFitToSizeType_AUTOFIT) );
                 }
 
-                if ( dynamic_cast<const SdrObjCustomShape* >(pTObj) ==  
nullptr )
+                if ( dynamic_cast<const SdrObjCustomShape* >(pTObj.get()) ==  
nullptr )
                 {
                     pTObj->SetMergedItem( makeSdrTextAutoGrowWidthItem( 
bAutoGrowWidth ) );
                     pTObj->SetMergedItem( makeSdrTextAutoGrowHeightItem( 
bAutoGrowHeight ) );
@@ -1119,12 +1118,12 @@ SdrObject* SdrEscherImport::ProcessObj( SvStream& rSt, 
DffObjData& rObjData, Svx
 
                 if ( nMinFrameHeight < 0 )
                     nMinFrameHeight = 0;
-                if ( dynamic_cast<const SdrObjCustomShape* >(pTObj) ==  
nullptr )
+                if ( dynamic_cast<const SdrObjCustomShape* >(pTObj.get()) ==  
nullptr )
                     pTObj->SetMergedItem( makeSdrTextMinFrameHeightItem( 
nMinFrameHeight ) );
 
                 if ( nMinFrameWidth < 0 )
                     nMinFrameWidth = 0;
-                if ( dynamic_cast<const SdrObjCustomShape* >(pTObj) ==  
nullptr )
+                if ( dynamic_cast<const SdrObjCustomShape* >(pTObj.get()) ==  
nullptr )
                     pTObj->SetMergedItem( makeSdrTextMinFrameWidthItem( 
nMinFrameWidth ) );
 
                 // set margins at the borders of the textbox
@@ -1134,9 +1133,9 @@ SdrObject* SdrEscherImport::ProcessObj( SvStream& rSt, 
DffObjData& rObjData, Svx
                 pTObj->SetMergedItem( makeSdrTextLowerDistItem( nTextBottom ) 
);
                 pTObj->SetMergedItem( SdrTextFixedCellHeightItem( true ) );
 
-                if ( dynamic_cast<const SdrObjCustomShape* >(pTObj) ==  
nullptr )
+                if ( dynamic_cast<const SdrObjCustomShape* >(pTObj.get()) ==  
nullptr )
                     pTObj->SetSnapRect( rTextRect );
-                pTObj = ReadObjText( &aTextObj, pTObj, rData.pPage );
+                pTObj = ReadObjText( &aTextObj, pTObj.get(), rData.pPage );
 
                 if ( pTObj )
                 {
@@ -1146,9 +1145,9 @@ SdrObject* SdrEscherImport::ProcessObj( SvStream& rSt, 
DffObjData& rObjData, Svx
                     snaprect of the object. Then we will use
                     ADJUST_CENTER instead of ADJUST_BLOCK.
                     */
-                    if ( dynamic_cast<const SdrObjCustomShape* >(pTObj) ==  
nullptr && !bFitShapeToText && !bWordWrap )
+                    if ( dynamic_cast<const SdrObjCustomShape* >(pTObj.get()) 
==  nullptr && !bFitShapeToText && !bWordWrap )
                     {
-                        SdrTextObj* pText = dynamic_cast<SdrTextObj*>( pTObj  
);
+                        SdrTextObj* pText = dynamic_cast<SdrTextObj*>( 
pTObj.get()  );
                         if ( pText )
                         {
                             if ( bVerticalText )
@@ -1179,7 +1178,7 @@ SdrObject* SdrEscherImport::ProcessObj( SvStream& rSt, 
DffObjData& rObjData, Svx
                     Degree100 nAngle = ( rObjData.nSpFlags & ShapeFlag::FlipV 
) ? -mnFix16Angle : mnFix16Angle; // #72116# vertical flip -> rotate by using 
the other way
                     nAngle += nTextRotationAngle;
 
-                    if ( dynamic_cast< const SdrObjCustomShape* >(pTObj) ==  
nullptr )
+                    if ( dynamic_cast< const SdrObjCustomShape* >(pTObj.get()) 
==  nullptr )
                     {
                         if ( rObjData.nSpFlags & ShapeFlag::FlipV )
                         {
@@ -1192,13 +1191,13 @@ SdrObject* SdrEscherImport::ProcessObj( SvStream& rSt, 
DffObjData& rObjData, Svx
                     }
                     if ( pRet )
                     {
-                        SdrObject* pGroup = new SdrObjGroup(*pSdrModel);
-                        pGroup->GetSubList()->NbcInsertObject( pRet );
-                        pGroup->GetSubList()->NbcInsertObject( pTObj );
+                        rtl::Reference<SdrObject> pGroup = new 
SdrObjGroup(*pSdrModel);
+                        pGroup->GetSubList()->NbcInsertObject( pRet.get() );
+                        pGroup->GetSubList()->NbcInsertObject( pTObj.get() );
                         pRet = pGroup;
                     }
                     else
-                        pRet = pTObj;
+                        pRet = pTObj.get();
                 }
             }
         }
@@ -1254,11 +1253,11 @@ SdrObject* SdrEscherImport::ProcessObj( SvStream& rSt, 
DffObjData& rObjData, Svx
             for (auto & pPtr : rPersistEntry.xSolverContainer->aCList)
             {
                 if ( rObjData.nShapeId == pPtr->nShapeC )
-                    pPtr->pCObj = pRet;
+                    pPtr->pCObj = pRet.get();
                 else
                 {
-                    SdrObject* pConnectObj = pRet;
-                    if ( pOriginalObj && dynamic_cast< const SdrObjGroup* 
>(pRet) !=  nullptr )
+                    SdrObject* pConnectObj = pRet.get();
+                    if ( pOriginalObj && dynamic_cast< const SdrObjGroup* 
>(pRet.get()) !=  nullptr )
                     {   /* check if the original object from the escherimport 
is part of the group object,
                         if this is the case, we will use the original object 
to connect to */
                         SdrObjListIter aIter( *pRet, 
SdrIterMode::DeepWithGroups );
@@ -1796,13 +1795,13 @@ static bool SdrPowerPointOLEDecompress( SvStream& 
rOutput, SvStream& rInput, sal
 }
 
 // #i32596# - add new parameter <_nCalledByGroup>
-SdrObject* SdrPowerPointImport::ImportOLE( sal_uInt32 nOLEId,
+rtl::Reference<SdrObject> SdrPowerPointImport::ImportOLE( sal_uInt32 nOLEId,
                                            const Graphic& rGraf,
                                            const tools::Rectangle& rBoundRect,
                                            const tools::Rectangle& rVisArea,
                                            const int /*_nCalledByGroup*/ ) 
const
 {
-    SdrObject* pRet = nullptr;
+    rtl::Reference<SdrObject> pRet;
 
     sal_uInt32 nOldPos = rStCtrl.Tell();
 
@@ -2908,16 +2907,16 @@ void SdrPowerPointImport::ImportPage( SdrPage* pRet, 
const PptSlidePersistEntry*
                                                 aShapeHd.SeekToBegOfRecord( 
rStCtrl );
                                                 sal_Int32 nShapeId;
                                                 
aProcessData.pTableRowProperties.reset();
-                                                SdrObject* pObj = ImportObj( 
rStCtrl, aProcessData, aEmpty, aEmpty, 0, &nShapeId );
+                                                rtl::Reference<SdrObject> pObj 
= ImportObj( rStCtrl, aProcessData, aEmpty, aEmpty, 0, &nShapeId );
                                                 if ( pObj )
                                                 {
                                                     if ( 
aProcessData.pTableRowProperties )
-                                                        pObj = 
CreateTable(pObj, aProcessData.pTableRowProperties.get(), 
aProcessData.rPersistEntry.xSolverContainer.get(), 
aProcessData.aBackgroundColoredObjects);
+                                                        pObj = 
CreateTable(pObj.get(), aProcessData.pTableRowProperties.get(), 
aProcessData.rPersistEntry.xSolverContainer.get(), 
aProcessData.aBackgroundColoredObjects);
 
-                                                    pRet->NbcInsertObject( 
pObj );
+                                                    pRet->NbcInsertObject( 
pObj.get() );
 
                                                     if( nShapeId )
-                                                        insertShapeId( 
nShapeId, pObj );
+                                                        insertShapeId( 
nShapeId, pObj.get() );
                                                 }
                                             }
                                             bool bSuccess = 
aShapeHd.SeekToEndOfRecord(rStCtrl);
@@ -2942,7 +2941,7 @@ void SdrPowerPointImport::ImportPage( SdrPage* pRet, 
const PptSlidePersistEntry*
                             {
                                 if (!rSlidePersist.pBObj)
                                 {
-                                    for (auto pObject : 
aProcessData.aBackgroundColoredObjects)
+                                    for (auto const & pObject : 
aProcessData.aBackgroundColoredObjects)
                                     {
                                         // The shape wants a background, but 
the slide doesn't have
                                         // one: default to white.
@@ -2966,15 +2965,15 @@ void SdrPowerPointImport::ImportPage( SdrPage* pRet, 
const PptSlidePersistEntry*
                                 for (auto & pPtr : 
rSlidePersist.xSolverContainer->aCList)
                                 {
                                     // check connections to the group object
-                                    if (pPtr->pAObj == rSlidePersist.pBObj)
+                                    if (pPtr->pAObj == 
rSlidePersist.pBObj.get())
                                         pPtr->pAObj = nullptr;
-                                    if (pPtr->pBObj == rSlidePersist.pBObj)
+                                    if (pPtr->pBObj == 
rSlidePersist.pBObj.get())
                                         pPtr->pBObj = nullptr;
-                                    if (pPtr->pCObj == rSlidePersist.pBObj)
+                                    if (pPtr->pCObj == 
rSlidePersist.pBObj.get())
                                         pPtr->pCObj = nullptr;
                                 }
                             }
-                            SdrObject::Free(rSlidePersist.pBObj);
+                            rSlidePersist.pBObj.clear();
                         }
                     }
                 }
@@ -3048,9 +3047,9 @@ sal_uInt16 SdrPowerPointImport::GetMasterPageIndex( 
sal_uInt16 nPageNum, PptPage
     return nIdx;
 }
 
-SdrObject* SdrPowerPointImport::ImportPageBackgroundObject( const SdrPage& 
rPage, sal_uInt32& nBgFileOffset )
+rtl::Reference<SdrObject> SdrPowerPointImport::ImportPageBackgroundObject( 
const SdrPage& rPage, sal_uInt32& nBgFileOffset )
 {
-    SdrObject* pRet = nullptr;
+    rtl::Reference<SdrObject> pRet;
     std::optional<SfxItemSet> pSet;
     sal_uInt64 nOldFPos = rStCtrl.Tell(); // remember FilePos for restoring it 
later
     DffRecordHeader aPageHd;
@@ -7517,9 +7516,12 @@ static void ApplyCellLineAttributes( const SdrObject* 
pLine, Reference< XTable >
     }
 }
 
-SdrObject* SdrPowerPointImport::CreateTable(SdrObject* pGroup, const 
sal_uInt32* pTableArry, SvxMSDffSolverContainer* pSolverContainer, 
std::vector<SdrObject*>& rBackgroundColoredObjects)
+rtl::Reference<SdrObject> SdrPowerPointImport::CreateTable(
+        SdrObject* pGroup, const sal_uInt32* pTableArry,
+        SvxMSDffSolverContainer* pSolverContainer,
+        std::vector<rtl::Reference<SdrObject>>& rBackgroundColoredObjects)
 {
-    SdrObject* pRet = pGroup;
+    rtl::Reference<SdrObject> pRet = pGroup;
 
     sal_uInt32 nRows = pTableArry[ 1 ];
     if (!nRows)
@@ -7551,7 +7553,7 @@ SdrObject* SdrPowerPointImport::CreateTable(SdrObject* 
pGroup, const sal_uInt32*
     if (aRows.empty())
         return pRet;
 
-    sdr::table::SdrTableObj* pTable = new sdr::table::SdrTableObj(*pSdrModel);
+    rtl::Reference<sdr::table::SdrTableObj> pTable = new 
sdr::table::SdrTableObj(*pSdrModel);
     pTable->uno_lock();
     Reference< XTable > xTable( pTable->getTable() );
 
@@ -7656,9 +7658,9 @@ SdrObject* SdrPowerPointImport::CreateTable(SdrObject* 
pGroup, const sal_uInt32*
                 //table when export by us. We should process this
                 //situation when importing.
                 if ( pPtr->pAObj == pGroup )
-                    pPtr->pAObj = pTable;
+                    pPtr->pAObj = pTable.get();
                 if ( pPtr->pBObj == pGroup )
-                    pPtr->pBObj = pTable;
+                    pPtr->pBObj = pTable.get();
             }
         }
         pTable->uno_unlock();
@@ -7672,16 +7674,13 @@ SdrObject* SdrPowerPointImport::CreateTable(SdrObject* 
pGroup, const sal_uInt32*
             SdrObject* pPartObj = aIter.Next();
             removeShapeId(pPartObj);
             // ofz#41510 make sure rBackgroundColoredObjects doesn't contain 
deleted objects
-            std::replace(rBackgroundColoredObjects.begin(), 
rBackgroundColoredObjects.end(), pPartObj, pRet);
+            std::replace(rBackgroundColoredObjects.begin(), 
rBackgroundColoredObjects.end(), pPartObj, pRet.get());
         }
-
-        SdrObject::Free( pGroup );
     }
     catch( const Exception& )
     {
         pTable->uno_unlock();
-        SdrObject* pObj = pTable;
-        SdrObject::Free( pObj );
+        pTable = nullptr;
     }
 
     return pRet;
diff --git a/filter/source/svg/svgexport.cxx b/filter/source/svg/svgexport.cxx
index 295c9dedbd93..023486f01879 100644
--- a/filter/source/svg/svgexport.cxx
+++ b/filter/source/svg/svgexport.cxx
@@ -860,8 +860,8 @@ bool SVGFilter::implExportWriterTextGraphic( const 
Reference< view::XSelectionSu
     if(pSvxDrawPage == nullptr || pSvxDrawPage->GetSdrPage() == nullptr)
         return false;
 
-    SdrGrafObj* pGraphicObj = new 
SdrGrafObj(pSvxDrawPage->GetSdrPage()->getSdrModelFromSdrPage(), aGraphic, 
tools::Rectangle( aPos, aSize ));
-    uno::Reference< drawing::XShape > xShape = 
GetXShapeForSdrObject(pGraphicObj);
+    rtl::Reference<SdrGrafObj> pGraphicObj = new 
SdrGrafObj(pSvxDrawPage->GetSdrPage()->getSdrModelFromSdrPage(), aGraphic, 
tools::Rectangle( aPos, aSize ));
+    uno::Reference< drawing::XShape > xShape = 
GetXShapeForSdrObject(pGraphicObj.get());
     uno::Reference< XPropertySet > xShapePropSet(xShape, uno::UNO_QUERY);
     xShapePropSet->setPropertyValue("Graphic", uno::Any(xGraphic));
 
diff --git a/filter/source/svg/svgfilter.cxx b/filter/source/svg/svgfilter.cxx
index bb87989bab2f..963a9ae2c4d4 100644
--- a/filter/source/svg/svgfilter.cxx
+++ b/filter/source/svg/svgfilter.cxx
@@ -291,15 +291,15 @@ bool SVGFilter::filterImpressOrDraw( const Sequence< 
PropertyValue >& rDescripto
 
             // create a SdrModel-GraphicObject to insert to page
             SdrPage* pTargetSdrPage(pSvxDrawPage->GetSdrPage());
-            std::unique_ptr< SdrGrafObj, SdrObjectFreeOp > aNewSdrGrafObj;
+            rtl::Reference< SdrGrafObj > aNewSdrGrafObj;
 
             // tdf#118232 only add an SdrGrafObj when we have Geometry
             if(!bContainsNoGeometry)
             {
-                aNewSdrGrafObj.reset(
+                aNewSdrGrafObj =
                     new SdrGrafObj(
                         pTargetSdrPage->getSdrModelFromSdrPage(),
-                        aGraphic));
+                        aGraphic);
             }
 
             // Evtl. adapt the GraphicPrefSize to target-MapMode of 
target-Model
@@ -355,7 +355,7 @@ bool SVGFilter::filterImpressOrDraw( const Sequence< 
PropertyValue >& rDescripto
                         aGraphicSize));
 
                 // insert to page (owner change of SdrGrafObj)
-                pTargetSdrPage->InsertObject(aNewSdrGrafObj.release());
+                pTargetSdrPage->InsertObject(aNewSdrGrafObj.get());
             }
 
             // done - set positive result now
diff --git a/framework/source/fwe/helper/undomanagerhelper.cxx 
b/framework/source/fwe/helper/undomanagerhelper.cxx
index 536c3116715f..582335f3d71e 100644
--- a/framework/source/fwe/helper/undomanagerhelper.cxx
+++ b/framework/source/fwe/helper/undomanagerhelper.cxx
@@ -36,6 +36,7 @@
 #include <svl/undo.hxx>
 #include <comphelper/diagnose_ex.hxx>
 #include <osl/conditn.hxx>
+#include <vcl/svapp.hxx>
 
 #include <functional>
 #include <mutex>
@@ -687,6 +688,7 @@ namespace framework
 
         {
             ::comphelper::FlagGuard aNotificationGuard( m_bAPIActionRunning );
+            SolarMutexGuard aGuard2;
             rUndoManager.Clear();
         }
 
diff --git a/include/filter/msfilter/msdffimp.hxx 
b/include/filter/msfilter/msdffimp.hxx
index 3dfd170bcb2a..492c64ebf724 100644
--- a/include/filter/msfilter/msdffimp.hxx
+++ b/include/filter/msfilter/msdffimp.hxx
@@ -37,6 +37,7 @@
 #include <filter/msfilter/escherex.hxx>
 #include <filter/msfilter/msfilterdllapi.h>
 #include <rtl/ustring.hxx>
+#include <rtl/ref.hxx>
 #include <sal/types.h>
 #include <svx/msdffdef.hxx>
 #include <vcl/errcode.hxx>
@@ -215,7 +216,7 @@ struct MSFILTER_DLLPUBLIC SvxMSDffImportRec
 {
     static const int RELTO_DEFAULT = 2;
 
-    SdrObject*      pObj;
+    rtl::Reference<SdrObject> pObj;
     std::optional<tools::Polygon>
                     pWrapPolygon;
     std::unique_ptr<char[]>
@@ -480,11 +481,11 @@ protected:
                                 sal_uInt64 nPosGroup,
                                 sal_uInt16 nDrawingContainerId );
 
-    SdrObject* ImportGraphic( SvStream&, SfxItemSet&, const DffObjData& );
+    rtl::Reference<SdrObject> ImportGraphic( SvStream&, SfxItemSet&, const 
DffObjData& );
     // #i32596# - pass <nCalledByGroup> to method
     // Needed in Writer's Microsoft Word import to avoid import of OLE objects
     // inside groups. Instead a graphic object is created.
-    virtual SdrObject* ImportOLE( sal_uInt32 nOLEId,
+    virtual rtl::Reference<SdrObject> ImportOLE( sal_uInt32 nOLEId,
                                   const Graphic& rGraf,
                                   const tools::Rectangle& rBoundRect,
                                   const tools::Rectangle& rVisArea,
@@ -508,7 +509,7 @@ protected:
                                         sal_uInt32 nDatLen,
                                         std::unique_ptr<char[]>& rpBuff,
                                         sal_uInt32& rBuffLen );
-    virtual SdrObject* ProcessObj( SvStream& rSt,
+    virtual rtl::Reference<SdrObject> ProcessObj( SvStream& rSt,
                                    DffObjData& rData,
                                    SvxMSDffClientData& rClientData,
                                    tools::Rectangle& rTextRect,
@@ -662,22 +663,22 @@ public:
     */
     static bool GetBLIPDirect(SvStream& rBLIPStream, Graphic& rData, 
tools::Rectangle* pVisArea = nullptr );
 
-    bool GetShape(sal_uLong nId, SdrObject*& rpData, SvxMSDffImportData& 
rData);
+    bool GetShape(sal_uLong nId, rtl::Reference<SdrObject>& rpData, 
SvxMSDffImportData& rData);
 
-    SdrObject* ImportObj( SvStream& rSt,
+    rtl::Reference<SdrObject> ImportObj( SvStream& rSt,
                           SvxMSDffClientData& rData,
                           tools::Rectangle& rClientRect,
                           const tools::Rectangle& rGlobalChildRect,
                           int nCalledByGroup,
                           sal_Int32* pShapeId);
-    SdrObject* ImportGroup( const DffRecordHeader& rHd,
+    rtl::Reference<SdrObject> ImportGroup( const DffRecordHeader& rHd,
                             SvStream& rSt,
                             SvxMSDffClientData& rData,
                             tools::Rectangle& rClientRect,
                             const tools::Rectangle& rGlobalChildRect,
                             int nCalledByGroup,
                             sal_Int32* pShapeId );
-    SdrObject* ImportShape( const DffRecordHeader& rHd,
+    rtl::Reference<SdrObject> ImportShape( const DffRecordHeader& rHd,
                             SvStream& rSt,
                             SvxMSDffClientData& rData,
                             tools::Rectangle& rClientRect,
@@ -712,7 +713,7 @@ public:
 
     void RemoveFromShapeOrder( SdrObject const * pObject ) const;
 
-    static SdrOle2Obj* CreateSdrOLEFromStorage(
+    static rtl::Reference<SdrOle2Obj> CreateSdrOLEFromStorage(
         SdrModel& rSdrModel,
         const OUString& rStorageName,
         tools::SvRef<SotStorage> const & rSrcStorage,
diff --git a/include/filter/msfilter/svdfppt.hxx 
b/include/filter/msfilter/svdfppt.hxx
index 6fa9ffaf4d59..6ac77727a2d7 100644
--- a/include/filter/msfilter/svdfppt.hxx
+++ b/include/filter/msfilter/svdfppt.hxx
@@ -374,7 +374,7 @@ struct PptSlidePersistEntry
     std::unique_ptr<sal_uInt32[]>
                         pPresentationObjects;   // if valid, this is a pointer 
to an array that includes the offsets to the presentation objects
                                                 // on this masterpage for each 
instance (0 - 8);
-    SdrObject*          pBObj;
+    rtl::Reference<SdrObject> pBObj;
 
     PptPageKind         ePageKind;
 
@@ -491,7 +491,7 @@ public:
     const PptFontEntityAtom*  GetFontEnityAtom( sal_uInt32 nNum ) const;
     void                RecolorGraphic( SvStream& rSt, sal_uInt32 nRecLen, 
Graphic& rGraph );
     virtual SdrObject*  ReadObjText( PPTTextObj* pTextObj, SdrObject* pObj, 
SdPageCapsule pPage ) const;
-    virtual SdrObject*  ProcessObj( SvStream& rSt, DffObjData& rData, 
SvxMSDffClientData& rClientData, tools::Rectangle& rTextRect, SdrObject* pObj ) 
override;
+    virtual rtl::Reference<SdrObject> ProcessObj( SvStream& rSt, DffObjData& 
rData, SvxMSDffClientData& rClientData, tools::Rectangle& rTextRect, SdrObject* 
pObj ) override;
     virtual void        ProcessClientAnchor2( SvStream& rSt, DffRecordHeader& 
rHd, DffObjData& rObj ) override;
     void                ImportHeaderFooterContainer( DffRecordHeader const & 
rHeader, HeaderFooterEntry& rEntry );
 };
@@ -542,7 +542,7 @@ struct MSFILTER_DLLPUBLIC ProcessData final : public 
SvxMSDffClientData
 {
     PptSlidePersistEntry&       rPersistEntry;
     SdPageCapsule               pPage;
-    ::std::vector< SdrObject* > aBackgroundColoredObjects;
+    ::std::vector< rtl::Reference<SdrObject> > aBackgroundColoredObjects;
     std::unique_ptr<sal_uInt32[]> pTableRowProperties;
 
     ProcessData( PptSlidePersistEntry& rP, SdPageCapsule pP ) :
@@ -605,7 +605,7 @@ protected:
     virtual SdrObject*      ReadObjText( PPTTextObj* pTextObj, SdrObject* 
pObj, SdPageCapsule pPage ) const override;
     // #i32596# - new parameter <_nCalledByGroup>, which
     // indicates, if the OLE object is imported inside a group object.
-    virtual SdrObject*      ImportOLE(
+    virtual rtl::Reference<SdrObject> ImportOLE(
                                 sal_uInt32 nOLEId,
                                 const Graphic& rGraf,
                                 const tools::Rectangle& rBoundRect,
@@ -631,7 +631,7 @@ public:
     sal_uInt16              GetPageCount( PptPageKind eKind = PPT_SLIDEPAGE ) 
const;
     void                    SetPageNum( sal_uInt16 nPageNum, PptPageKind = 
PPT_SLIDEPAGE );
     Size                    GetPageSize() const;
-    SdrObject*              ImportPageBackgroundObject(
+    rtl::Reference<SdrObject> ImportPageBackgroundObject(
                                 const SdrPage& rPage,
                                 sal_uInt32& nBgFileOffset
                             );
@@ -649,11 +649,11 @@ public:
     virtual bool            GetColorFromPalette(sal_uInt16 nNum, Color& 
rColor) const override;
     virtual bool            SeekToShape( SvStream& rSt, SvxMSDffClientData* 
pClientData, sal_uInt32 nId ) const override;
     virtual const PptSlideLayoutAtom*   GetSlideLayoutAtom() const override;
-    SdrObject*              CreateTable(
+    rtl::Reference<SdrObject> CreateTable(
                                 SdrObject* pGroupObject,
                                 const sal_uInt32* pTableArry,
                                 SvxMSDffSolverContainer* pSolverContainer,
-                                std::vector<SdrObject*>& 
rBackgroundColoredObjects
+                                std::vector<rtl::Reference<SdrObject>>& 
rBackgroundColoredObjects
                             );
     virtual bool ReadFormControl( tools::SvRef<SotStorage>& rSrc1, 
css::uno::Reference< css::form::XFormComponent > & rFormComp ) const = 0;
 };
diff --git a/include/svx/EnhancedCustomShape2d.hxx 
b/include/svx/EnhancedCustomShape2d.hxx
index abe9319407ff..7855daacbeae 100644
--- a/include/svx/EnhancedCustomShape2d.hxx
+++ b/include/svx/EnhancedCustomShape2d.hxx
@@ -142,11 +142,11 @@ class SVXCORE_DLLPUBLIC EnhancedCustomShape2d final : 
public SfxItemSet
         SAL_DLLPRIVATE void CreateSubPath(
             sal_Int32& rSrcPt,
             sal_Int32& rSegmentInd,
-            std::vector< std::pair< SdrPathObjUniquePtr, double> >& 
rObjectList,
+            std::vector< std::pair< rtl::Reference<SdrPathObj>, double> >& 
rObjectList,
             bool bLineGeometryNeededOnly,
             bool bSortFilledObjectsToBack,
             sal_Int32 nIndex);
-        SAL_DLLPRIVATE SdrObjectUniquePtr CreatePathObj( bool 
bLineGeometryNeededOnly );
+        SAL_DLLPRIVATE rtl::Reference<SdrObject> CreatePathObj( bool 
bLineGeometryNeededOnly );
         SAL_DLLPRIVATE void     ApplyShapeAttributes( const 
SdrCustomShapeGeometryItem& rItem );
 
         SAL_DLLPRIVATE void     SetPathSize( sal_Int32 nIndex = 0 );
@@ -187,8 +187,8 @@ class SVXCORE_DLLPUBLIC EnhancedCustomShape2d final : 
public SfxItemSet
         SAL_DLLPRIVATE bool     IsFlipHorz() const { return bFlipH; };
         SAL_DLLPRIVATE Degree100 GetRotateAngle() const { return nRotateAngle; 
};
 
-        SdrObjectUniquePtr      CreateLineGeometry();
-        SdrObjectUniquePtr      CreateObject( bool bLineGeometryNeededOnly );
+        rtl::Reference<SdrObject>      CreateLineGeometry();
+        rtl::Reference<SdrObject>      CreateObject( bool 
bLineGeometryNeededOnly );
         void                    ApplyGluePoints( SdrObject* pObj );
         tools::Rectangle        GetTextRect() const;
         const tools::Rectangle& GetLogicRect() const { return aLogicRect; }
diff --git a/include/svx/compressgraphicdialog.hxx 
b/include/svx/compressgraphicdialog.hxx
index 073b330cda2d..3319a41a431c 100644
--- a/include/svx/compressgraphicdialog.hxx
+++ b/include/svx/compressgraphicdialog.hxx
@@ -95,7 +95,7 @@ public:
     CompressGraphicsDialog( weld::Window* pParent, Graphic aGraphic, Size 
aViewSize100mm, tools::Rectangle const & rCropRectangle, SfxBindings& rBindings 
);
     virtual ~CompressGraphicsDialog() override;
 
-    SdrGrafObj* GetCompressedSdrGrafObj();
+    rtl::Reference<SdrGrafObj> GetCompressedSdrGrafObj();
     Graphic GetCompressedGraphic();
 
     tools::Rectangle GetScaledCropRectangle() const;
diff --git a/include/svx/connctrl.hxx b/include/svx/connctrl.hxx
index 44768922f317..8e416674b1b2 100644
--- a/include/svx/connctrl.hxx
+++ b/include/svx/connctrl.hxx
@@ -40,7 +40,7 @@ class SAL_WARN_UNUSED SVX_DLLPUBLIC SvxXConnectionPreview 
final : public weld::C
 
 private:
     MapMode aNewMapMode;
-    SdrEdgeObj*         pEdgeObj;
+    rtl::Reference<SdrEdgeObj>  pEdgeObj;
     rtl::Reference<SdrPage> mxSdrPage;
     const SdrView*      pView;
 
diff --git a/include/svx/cube3d.hxx b/include/svx/cube3d.hxx
index 9842b26f0e55..b984a74c65d9 100644
--- a/include/svx/cube3d.hxx
+++ b/include/svx/cube3d.hxx
@@ -69,9 +69,9 @@ public:
     E3dCubeObj(SdrModel& rSdrModel);
 
     virtual SdrObjKind GetObjIdentifier() const override;
-    virtual SdrObjectUniquePtr DoConvertToPolyObj(bool bBezier, bool bAddText) 
const override;
+    virtual rtl::Reference<SdrObject> DoConvertToPolyObj(bool bBezier, bool 
bAddText) const override;
 
-    virtual E3dCubeObj* CloneSdrObject(SdrModel& rTargetModel) const override;
+    virtual rtl::Reference<SdrObject> CloneSdrObject(SdrModel& rTargetModel) 
const override;
 
     // Set local parameters with geometry recreation
     void SetCubePos(const basegfx::B3DPoint& rNew);
diff --git a/include/svx/dlgctl3d.hxx b/include/svx/dlgctl3d.hxx
index afa246b1601a..5d6449e63cee 100644
--- a/include/svx/dlgctl3d.hxx
+++ b/include/svx/dlgctl3d.hxx
@@ -41,8 +41,8 @@ protected:
     std::unique_ptr<FmFormModel> mpModel;
     rtl::Reference<FmFormPage> mxFmPage;
     std::unique_ptr<E3dView> mp3DView;
-    E3dScene*               mpScene;
-    E3dObject*              mp3DObj;
+    rtl::Reference<E3dScene>  mpScene;
+    rtl::Reference<E3dObject>  mp3DObj;
     SvxPreviewObjectType    mnObjectType;
 
     void Construct();
@@ -72,9 +72,9 @@ class SAL_WARN_UNUSED SVX_DLLPUBLIC Svx3DLightControl final : 
public Svx3DPrevie
     sal_uInt32                  maSelectedLight;
 
     // extra objects for light control
-    E3dObject*                  mpExpansionObject;
-    E3dObject*                  mpLampBottomObject;
-    E3dObject*                  mpLampShaftObject;
+    rtl::Reference<E3dObject>   mpExpansionObject;
+    rtl::Reference<E3dObject>   mpLampBottomObject;
+    rtl::Reference<E3dObject>   mpLampShaftObject;
     std::vector< E3dObject* >   maLightObjects;
 
     // 3d rotations of object
diff --git a/include/svx/dlgctrl.hxx b/include/svx/dlgctrl.hxx
index 9787e025f915..26371185c7f0 100644
--- a/include/svx/dlgctrl.hxx
+++ b/include/svx/dlgctrl.hxx
@@ -333,9 +333,9 @@ public:
 class SAL_WARN_UNUSED SVX_DLLPUBLIC SvxXLinePreview final : public 
SvxPreviewBase
 {
 private:
-    SdrPathObj*                                     mpLineObjA;
-    SdrPathObj*                                     mpLineObjB;
-    SdrPathObj*                                     mpLineObjC;
+    rtl::Reference<SdrPathObj>                      mpLineObjA;
+    rtl::Reference<SdrPathObj>                      mpLineObjB;
+    rtl::Reference<SdrPathObj>                      mpLineObjC;
 
     Graphic*                                        mpGraphic;
     bool                                            mbWithSymbol;
@@ -359,7 +359,7 @@ public:
 class SAL_WARN_UNUSED SVX_DLLPUBLIC SvxXRectPreview final : public 
SvxPreviewBase
 {
 private:
-    SdrObject* mpRectangleObject;
+    rtl::Reference<SdrObject> mpRectangleObject;
 
 public:
     SvxXRectPreview();
@@ -383,8 +383,8 @@ class SAL_WARN_UNUSED SVX_DLLPUBLIC SvxXShadowPreview final 
: public SvxPreviewB
 private:
     Point maShadowOffset;
 
-    SdrObject* mpRectangleObject;
-    SdrObject* mpRectangleShadow;
+    rtl::Reference<SdrObject> mpRectangleObject;
+    rtl::Reference<SdrObject> mpRectangleShadow;
 
 public:
     SvxXShadowPreview();
diff --git a/include/svx/extedit.hxx b/include/svx/extedit.hxx
index 0168068f66c8..04fd9dfb8e54 100644
--- a/include/svx/extedit.hxx
+++ b/include/svx/extedit.hxx
@@ -13,6 +13,7 @@
 #include <svx/svxdllapi.h>
 #include <svl/lstner.hxx>
 #include <rtl/ustring.hxx>
+#include <rtl/ref.hxx>
 #include <memory>
 
 class Graphic;
@@ -41,6 +42,7 @@ public:
 
 class FmFormView;
 class SdrObject;
+class SdrGrafObj;
 
 class SAL_WARN_UNUSED SVXCORE_DLLPUBLIC SdrExternalToolEdit final
 :   public ExternalToolEdit
@@ -48,7 +50,7 @@ class SAL_WARN_UNUSED SVXCORE_DLLPUBLIC SdrExternalToolEdit 
final
 {
 private:
     FmFormView* m_pView;
-    SdrObject*  m_pObj;
+    rtl::Reference<SdrGrafObj>  m_pObj;
 
     SAL_DLLPRIVATE virtual void Update(Graphic&) override;
     SAL_DLLPRIVATE virtual void Notify(SfxBroadcaster&, const SfxHint&) 
override;
@@ -56,7 +58,7 @@ private:
 public:
     SdrExternalToolEdit(
         FmFormView* pView,
-        SdrObject* pObj);
+        SdrGrafObj* pObj);
 };
 
 #endif
diff --git a/include/svx/fmdpage.hxx b/include/svx/fmdpage.hxx
index ae864e611528..3842e8b0b02e 100644
--- a/include/svx/fmdpage.hxx
+++ b/include/svx/fmdpage.hxx
@@ -34,7 +34,7 @@ protected:
 
     // Creating a SdrObject based on a Description. Can be used by derived 
classes to
     // support own css::drawing::Shapes (for example Controls)
-    virtual SdrObject *CreateSdrObject_( const css::uno::Reference< 
css::drawing::XShape > & xShape ) override;
+    virtual rtl::Reference<SdrObject> CreateSdrObject_( const 
css::uno::Reference< css::drawing::XShape > & xShape ) override;
 
     // The following method is called when a SvxShape object should be created.
     // Derived classes can create a derivation or an object aggregating 
SvxShape.
diff --git a/include/svx/fmobjfac.hxx b/include/svx/fmobjfac.hxx
index f165cf7b2247..003f6b258642 100644
--- a/include/svx/fmobjfac.hxx
+++ b/include/svx/fmobjfac.hxx
@@ -22,6 +22,7 @@
 
 #include <tools/link.hxx>
 #include <svx/svxdllapi.h>
+#include <rtl/ref.hxx>
 
 class SdrObject;
 struct SdrObjCreatorParams;
@@ -31,7 +32,8 @@ class SVX_DLLPUBLIC FmFormObjFactory
 public:
     FmFormObjFactory();
 
-    DECL_DLLPRIVATE_STATIC_LINK(FmFormObjFactory, MakeObject, 
SdrObjCreatorParams, SdrObject*);
+    DECL_DLLPRIVATE_STATIC_LINK(FmFormObjFactory, MakeObject, 
SdrObjCreatorParams,
+                                rtl::Reference<SdrObject>);
 };
 
 #endif // _FM_FMOBJFAC_HXX
diff --git a/include/svx/fmpage.hxx b/include/svx/fmpage.hxx
index f8b3c11cb72f..1f2978c05c75 100644
--- a/include/svx/fmpage.hxx
+++ b/include/svx/fmpage.hxx
@@ -54,7 +54,7 @@ public:
 
     virtual void    InsertObject(SdrObject* pObj, size_t nPos = SAL_MAX_SIZE) 
override;
 
-    virtual SdrObject* RemoveObject(size_t nObjNum) override;
+    virtual rtl::Reference<SdrObject> RemoveObject(size_t nObjNum) override;
 
     // access to all forms
     const css::uno::Reference< css::form::XForms>& GetForms( bool 
_bForceCreate = true ) const;
diff --git a/include/svx/fmview.hxx b/include/svx/fmview.hxx
index 77928837d7d7..2c2b26f20f41 100644
--- a/include/svx/fmview.hxx
+++ b/include/svx/fmview.hxx
@@ -71,15 +71,15 @@ public:
         @deprecated
             This method is deprecated. Use the version with an 
ODataAccessDescriptor instead.
     */
-    SdrObjectUniquePtr CreateFieldControl(std::u16string_view rFieldDesc) 
const;
+    rtl::Reference<SdrObject> CreateFieldControl(std::u16string_view 
rFieldDesc) const;
 
     /** create a control pair (label/bound control) for the database field 
description given.
     */
-    SdrObjectUniquePtr CreateFieldControl( const svx::ODataAccessDescriptor& 
_rColumnDescriptor );
+    rtl::Reference<SdrObject> CreateFieldControl( const 
svx::ODataAccessDescriptor& _rColumnDescriptor );
 
     /** create a control pair (label/bound control) for the xforms description 
given.
     */
-    SdrObjectUniquePtr CreateXFormsControl( const svx::OXFormsDescriptor 
&_rDesc );
+    rtl::Reference<SdrObject> CreateXFormsControl( const 
svx::OXFormsDescriptor &_rDesc );
 
     virtual void MarkListHasChanged() override;
     virtual void AddWindowToPaintView(OutputDevice* pNewWin, vcl::Window* 
pWindow) override;
@@ -99,8 +99,8 @@ public:
         // demand clear, hand over a SdrMldel&
         SdrModel& _rModel,
 
-        std::unique_ptr<SdrUnoObj, SdrObjectFreeOp>& _rpLabel,
-        std::unique_ptr<SdrUnoObj, SdrObjectFreeOp>& _rpControl
+        rtl::Reference<SdrUnoObj>& _rpLabel,
+        rtl::Reference<SdrUnoObj>& _rpControl
     );
 
     virtual SdrPageView* ShowSdrPage(SdrPage* pPage) override;
diff --git a/include/svx/fontworkgallery.hxx b/include/svx/fontworkgallery.hxx
index 78e0370dbac5..1eb90f6476e0 100644
--- a/include/svx/fontworkgallery.hxx
+++ b/include/svx/fontworkgallery.hxx
@@ -49,7 +49,7 @@ class SAL_WARN_UNUSED SVXCORE_DLLPUBLIC FontWorkGalleryDialog 
final : public wel
     SdrView&            mrSdrView;
 
     bool                mbInsertIntoPage;
-    SdrObject*          mpSdrObject;
+    rtl::Reference<SdrObject> mxSdrObject;
     SdrModel*           mpDestModel;
 
     std::vector<VclPtr< VirtualDevice >> maFavoritesHorizontal;
@@ -70,7 +70,7 @@ public:
 
     // SJ: if the SdrObject** is set, the SdrObject is not inserted into the 
page when executing the dialog
     void SetSdrObjectRef( SdrModel* pModel );
-    SdrObject* GetSdrObjectRef() { return mpSdrObject; }
+    SdrObject* GetSdrObjectRef() { return mxSdrObject.get(); }
 };
 
 }
diff --git a/include/svx/lathe3d.hxx b/include/svx/lathe3d.hxx
index 7b1396a68ac4..9bd17307ceee 100644
--- a/include/svx/lathe3d.hxx
+++ b/include/svx/lathe3d.hxx
@@ -101,9 +101,9 @@ public:
 
     virtual SdrObjKind GetObjIdentifier() const override;
 
-    virtual E3dLatheObj* CloneSdrObject(SdrModel& rTargetModel) const override;
+    virtual rtl::Reference<SdrObject> CloneSdrObject(SdrModel& rTargetModel) 
const override;
 
-    virtual SdrObjectUniquePtr DoConvertToPolyObj(bool bBezier, bool bAddText) 
const override;
+    virtual rtl::Reference<SdrObject> DoConvertToPolyObj(bool bBezier, bool 
bAddText) const override;
 
     // TakeObjName...() is for the display in the UI, for example "3 frames 
selected".
     virtual OUString TakeObjNameSingul() const override;
@@ -115,7 +115,7 @@ public:
 
     // break up
     virtual bool IsBreakObjPossible() override;
-    virtual std::unique_ptr<SdrAttrObj,SdrObjectFreeOp> GetBreakObj() override;
+    virtual rtl::Reference<SdrAttrObj> GetBreakObj() override;
 };
 
 #endif // INCLUDED_SVX_LATHE3D_HXX
diff --git a/include/svx/measctrl.hxx b/include/svx/measctrl.hxx
index ccdcab46f5fd..a6f25718596b 100644
--- a/include/svx/measctrl.hxx
+++ b/include/svx/measctrl.hxx
@@ -35,7 +35,7 @@ class SVX_DLLPUBLIC SvxXMeasurePreview final : public 
weld::CustomWidgetControll
 private:
     MapMode m_aMapMode;
     std::unique_ptr<SdrModel> pModel;
-    std::unique_ptr<SdrMeasureObj, SdrObjectFreeOp> pMeasureObj;
+    rtl::Reference<SdrMeasureObj> pMeasureObj;
 
     void ResizeImpl(const Size& rSize);
 
diff --git a/include/svx/obj3d.hxx b/include/svx/obj3d.hxx
index 29feec983475..13ffc73c9879 100644
--- a/include/svx/obj3d.hxx
+++ b/include/svx/obj3d.hxx
@@ -125,7 +125,7 @@ public:
     // TakeObjName...() is for the display in the UI, for example "3 frames 
selected".
     virtual OUString TakeObjNameSingul() const override;
     virtual OUString TakeObjNamePlural() const override;
-    virtual E3dObject* CloneSdrObject(SdrModel& rTargetModel) const override;
+    virtual rtl::Reference<SdrObject> CloneSdrObject(SdrModel& rTargetModel) 
const override;
 
     virtual std::unique_ptr<SdrObjGeoData> NewGeoData() const override;
     virtual void          SaveGeoData(SdrObjGeoData& rGeo) const override;
@@ -137,7 +137,7 @@ public:
 
     // break up
     virtual bool IsBreakObjPossible();
-    virtual std::unique_ptr<SdrAttrObj,SdrObjectFreeOp> GetBreakObj();
+    virtual rtl::Reference<SdrAttrObj> GetBreakObj();
 };
 
 /*************************************************************************
@@ -180,7 +180,7 @@ public:
     virtual SdrObjKind GetObjIdentifier() const override;
     virtual void RecalcSnapRect() override;
 
-    virtual E3dCompoundObject* CloneSdrObject(SdrModel& rTargetModel) const 
override;
+    virtual rtl::Reference<SdrObject> CloneSdrObject(SdrModel& rTargetModel) 
const override;
 };
 
 #endif // INCLUDED_SVX_OBJ3D_HXX
diff --git a/include/svx/objfac3d.hxx b/include/svx/objfac3d.hxx
index 24b14de5a46b..084782e66069 100644
--- a/include/svx/objfac3d.hxx
+++ b/include/svx/objfac3d.hxx
@@ -20,6 +20,7 @@
 #ifndef INCLUDED_SVX_OBJFAC3D_HXX
 #define INCLUDED_SVX_OBJFAC3D_HXX
 
+#include <rtl/ref.hxx>
 #include <svx/svxdllapi.h>
 #include <tools/link.hxx>
 
@@ -37,7 +38,8 @@ class SVXCORE_DLLPUBLIC E3dObjFactory
 public:
     E3dObjFactory();
 
-    DECL_DLLPRIVATE_STATIC_LINK(E3dObjFactory, MakeObject, 
SdrObjCreatorParams, SdrObject*);
+    DECL_DLLPRIVATE_STATIC_LINK(E3dObjFactory, MakeObject, SdrObjCreatorParams,
+                                rtl::Reference<SdrObject>);
 };
 
 #endif // INCLUDED_SVX_OBJFAC3D_HXX

... etc. - the rest is truncated

Reply via email to