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>
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index ac89e28..afacfec 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -394,6 +394,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();
}