diff --git a/scribus/tocgenerator.cpp b/scribus/tocgenerator.cpp
index c5f6c7e9a..e10b87250 100644
--- a/scribus/tocgenerator.cpp
+++ b/scribus/tocgenerator.cpp
@@ -83,9 +83,7 @@ void TOCGenerator::generateByAttribute()
 		const PageItem *currentDocItem;
 		QMap<QString, QString> tocMap;
 
-		auto pageCounter = std::make_unique<int[]>(m_doc->DocPages.count());
-		for (int i = 0; i < m_doc->DocPages.count(); ++i)
-			pageCounter[i] = 0;
+		auto pageCounter = std::vector<int>(m_doc->DocPages.count(), 0);
 
 		int pageNumberWidth = QString("%1").arg(m_doc->DocPages.count()).length();
 
@@ -119,7 +117,7 @@ void TOCGenerator::generateByAttribute()
 				//First is the page of the item
 				//Second is an incremented counter for the item so multiple per page works
 				//Third is the section based page number which is actually used in the TOC.
-				QString tocID = QString("%1").arg(pageCounter[currentDocItem->OwnPage]++, 3 , 10, QChar('0'));
+				QString tocID = QString("%1").arg(pageCounter.at(currentDocItem->OwnPage)++, 3 , 10, QChar('0'));
 				QString key = QString("%1,%2,%3").arg(pageID, tocID, sectionID);
 				tocMap.insert(key, objAttr.value);
 			}
@@ -227,9 +225,7 @@ void TOCGenerator::generateByStyle()
 		QMap<QString, QString> styleMap;
 		QMap<QString, TOCPageLocation> pageLocationMap;
 
-		auto pageCounter = std::make_unique<int[]>(m_doc->DocPages.count());
-		for (int i = 0; i < m_doc->DocPages.count(); ++i)
-			pageCounter[i] = 0;
+		auto pageCounter = std::vector<int>(m_doc->DocPages.count(), 0);
 
 		//Set up the gtWriter instance with the selected paragraph style
 		gtWriter writer(false, tocFrame);
@@ -290,7 +286,7 @@ void TOCGenerator::generateByStyle()
 				QString pname(item->itemText.paragraphStyle(i).parentStyle()->name());
 				QString pageID = QString("%1").arg(item->OwnPage + m_doc->FirstPnum, pageNumberWidth);
 				QString sectionID = m_doc->getSectionPageNumberForPageIndex(item->OwnPage);
-				QString tocID = QString("%1").arg(pageCounter[item->OwnPage]++, 3, 10, QChar('0'));
+				QString tocID = QString("%1").arg(pageCounter.at(item->OwnPage)++, 3, 10, QChar('0'));
 				QString key = QString("%1,%2,%3").arg(pageID, tocID, sectionID);
 				paraText.remove(SpecialChars::COLBREAK);
 				paraText.remove(SpecialChars::FRAMEBREAK);
