purge shared string pool if ScDocument is closed (tdf#125428)

Especially with the testcases given in the bugreport the undo history
would keep many unused shared strings.

Change-Id: I57fcad73532fdcbad0a1298fbd06cb35c058bf96
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95045
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
(cherry picked from commit 861fbd998f2b526c2aea073c9471613bf728fa75)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95323
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index cc45c83..3cbe637 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -390,6 +390,9 @@
    SAL_WARN_IF( pAutoNameCache, "sc.core", "AutoNameCache still set in dtor" );

    mpFormulaGroupCxt.reset();
    // Purge unused items if the string pool will be still used (e.g. by undo history).
    if(mpCellStringPool.use_count() > 1)
        mpCellStringPool->purge();
    mpCellStringPool.reset();
}