[Libreoffice-commits] core.git: sw/inc sw/source

Jian Fang Zhang zhangjf at apache.org
Wed Jun 5 03:36:15 PDT 2013


 sw/inc/doc.hxx                   |    8 +++---
 sw/source/core/doc/docnew.cxx    |    2 +
 sw/source/core/doc/docxforms.cxx |   51 +++++++++++++++++++++++++++++++++++++--
 3 files changed, 56 insertions(+), 5 deletions(-)

New commits:
commit 6e426582ec76be20c08d71ad7399b1bd008dfc75
Author: Jian Fang Zhang <zhangjf at apache.org>
Date:   Fri Sep 14 12:26:29 2012 +0000

    Resolves: #i113606# in SwDoc dtor release the cyclic reference...
    
    between XFormModel and bindings/submissions
    
    Patch by: zhangjf
    Review by: zhangjf
    
    (cherry picked from commit adc0946638e8817d5e57b0003b414249ac481df0)
    
    Conflicts:
    	sw/inc/doc.hxx
    	sw/source/core/doc/docnew.cxx
    	sw/source/core/doc/docxforms.cxx
    
    Change-Id: I3124daea8925b1efd8e151f3064582786d461718

diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index f0b97f0..c41615b 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -2036,12 +2036,14 @@ public:
 
     com::sun::star::uno::Reference< com::sun::star::linguistic2::XProofreadingIterator > GetGCIterator() const;
 
-    /// is this an XForms document?
+    /// #i31958# is this an XForms document?
     bool isXForms() const;
 
-    /// initialize XForms models; turn this into an XForms document
+    /// #i31958# initialize XForms models; turn this into an XForms document
     void initXForms( bool bCreateDefaultModel );
-    // access methods for XForms model(s)
+
+    /// #i113606# for disposing XForms
+    void disposeXForms( );
 
     //Update all the page masters
     void SetDefaultPageMode(bool bSquaredPageMode);
diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx
index 94ebfea..9835e6d 100644
--- a/sw/source/core/doc/docnew.cxx
+++ b/sw/source/core/doc/docnew.cxx
@@ -673,6 +673,8 @@ SwDoc::~SwDoc()
     }
     maListStyleLists.clear();
 
+    disposeXForms(); // #i113606#, dispose the XForms objects
+
     delete mpPrtData;
     delete mpNumberFormatter;
     delete mpFtnInfo;
diff --git a/sw/source/core/doc/docxforms.cxx b/sw/source/core/doc/docxforms.cxx
index e3d9601..416bc2e 100644
--- a/sw/source/core/doc/docxforms.cxx
+++ b/sw/source/core/doc/docxforms.cxx
@@ -29,7 +29,7 @@
 #include <com/sun/star/xforms/XForms.hpp>
 #include <comphelper/processfactory.hxx>
 #include <tools/diagnose_ex.h>
-
+#include <com/sun/star/container/XIndexAccess.hpp>
 
 using namespace ::com::sun::star;
 
@@ -42,7 +42,7 @@ using container::XNameContainer;
 using xforms::XModel2;
 using frame::XModule;
 using xforms::XFormsUIHelper1;
-
+using com::sun::star::container::XIndexAccess;
 
 Reference<XNameContainer> SwDoc::getXForms() const
 {
@@ -94,4 +94,51 @@ void SwDoc::initXForms( bool bCreateDefaultModel )
     }
 }
 
+// #i113606#, to release the cyclic reference between XFormModel and bindings/submissions.
+void SwDoc::disposeXForms( )
+{
+    // get XForms models
+    if( mxXForms.is() )
+    {
+        // iterate over all models
+        uno::Sequence<OUString> aNames = mxXForms->getElementNames();
+        const OUString* pNames = aNames.getConstArray();
+        sal_Int32 nNames = aNames.getLength();
+        for( sal_Int32 n = 0; (n < nNames); n++ )
+        {
+            Reference< xforms::XModel > xModel(
+                mxXForms->getByName( pNames[n] ), UNO_QUERY );
+
+            if( xModel.is() )
+            {
+                // ask model for bindings
+                Reference< XIndexAccess > xBindings(
+                         xModel->getBindings(), UNO_QUERY );
+
+                //
+                // Then release them one by one
+                //
+                int nCount = xBindings->getCount();
+                for( int i = nCount-1; i >= 0; i-- )
+                {
+                    xModel->getBindings()->remove(xBindings->getByIndex( i ));
+                }
+
+                // ask model for Submissions
+                Reference< XIndexAccess > xSubmissions(
+                         xModel->getSubmissions(), UNO_QUERY );
+
+                //
+                // Then release them one by one
+                //
+                nCount = xSubmissions->getCount();
+                for( int i = nCount-1; i >= 0; i-- )
+                {
+                    xModel->getSubmissions()->remove(xSubmissions->getByIndex( i ));
+                }
+            }
+        }
+    }
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list