Fixed some errors I made with cleanup.
This commit is contained in:
+3
-43
@@ -383,53 +383,13 @@ class EpubParser:
|
||||
def cleanup(self):
|
||||
"""Clean up temporary files and memory"""
|
||||
try:
|
||||
# Clear BeautifulSoup objects and other memory references
|
||||
if hasattr(self, 'soup'):
|
||||
del self.soup
|
||||
self.soup = None
|
||||
if hasattr(self, 'rootfile'):
|
||||
del self.rootfile
|
||||
self.rootfile = None
|
||||
if hasattr(self, 'metadataTag'):
|
||||
del self.metadataTag
|
||||
self.metadataTag = None
|
||||
if hasattr(self, 'manifestTag'):
|
||||
del self.manifestTag
|
||||
self.manifestTag = None
|
||||
if hasattr(self, 'spineTag'):
|
||||
del self.spineTag
|
||||
self.spineTag = None
|
||||
if hasattr(self, 'tocNav'):
|
||||
del self.tocNav
|
||||
self.tocNav = None
|
||||
if hasattr(self, 'navMap'):
|
||||
del self.navMap
|
||||
self.navMap = None
|
||||
|
||||
# Clear book content and references
|
||||
if self.book:
|
||||
if hasattr(self.book, 'chapters'):
|
||||
for chapter in self.book.chapters:
|
||||
if hasattr(chapter, 'paragraphs'):
|
||||
chapter.paragraphs.clear()
|
||||
self.book.chapters.clear()
|
||||
self.book = None
|
||||
|
||||
# Clear dictionaries and lists
|
||||
if hasattr(self, 'tocMap'):
|
||||
self.tocMap.clear()
|
||||
if hasattr(self, 'manifest'):
|
||||
self.manifest.clear()
|
||||
if hasattr(self, 'spine'):
|
||||
self.spine.clear()
|
||||
|
||||
# Force garbage collection
|
||||
# Force garbage collection to clean up local variables
|
||||
import gc
|
||||
gc.collect()
|
||||
|
||||
|
||||
except Exception as e:
|
||||
print(f"Warning: Error during memory cleanup: {e}")
|
||||
|
||||
|
||||
# Clean up temp directory
|
||||
if self.tempDir and Path(self.tempDir).exists():
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user