diff --git a/src/xercesc/util/NameIdPool.c b/src/xercesc/util/NameIdPool.c
index dc7ed04e53c2f5d0a4bcc05037b2b541bb445315..17d035e3e77aecfb081ed057a7c75916fb026b24 100644
--- a/src/xercesc/util/NameIdPool.c
+++ b/src/xercesc/util/NameIdPool.c
@@ -118,6 +118,8 @@ NameIdPool<TElem>::containsKey(const XMLCh* const key) const
 
 template <class TElem> void NameIdPool<TElem>::removeAll()
 {
+    if (fIdCounter == 0) return;
+
     // Clean up the buckets first
     for (unsigned int buckInd = 0; buckInd < fHashModulus; buckInd++)
     {
diff --git a/src/xercesc/util/RefHash3KeysIdPool.c b/src/xercesc/util/RefHash3KeysIdPool.c
index 5b38560d0d5d1398d210e5dc5a14225b520f4225..ac73cfa71771cd4b93d4d4d3b253ba3651977152 100644
--- a/src/xercesc/util/RefHash3KeysIdPool.c
+++ b/src/xercesc/util/RefHash3KeysIdPool.c
@@ -181,6 +181,8 @@ containsKey(const void* const key1, const int key2, const int key3) const
 
 template <class TVal> void RefHash3KeysIdPool<TVal>::removeAll()
 {
+    if (fIdCounter == 0) return;
+
     // Clean up the buckets first
     for (unsigned int buckInd = 0; buckInd < fHashModulus; buckInd++)
     {