fix the issue
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import sys
|
||||
import os
|
||||
import psutil
|
||||
import gc
|
||||
import time
|
||||
|
||||
sys.path.insert(0, os.path.abspath('gateway'))
|
||||
import pdfengine
|
||||
|
||||
def get_memory_mb():
|
||||
process = psutil.Process(os.getpid())
|
||||
return process.memory_info().rss / (1024 * 1024)
|
||||
|
||||
def validate_memory(iterations=1000):
|
||||
pdf_file = os.path.abspath("corpus/fonts/utf-8.pdf")
|
||||
|
||||
print("Memory Validation Test")
|
||||
print("-" * 30)
|
||||
|
||||
gc.collect()
|
||||
start_mem = get_memory_mb()
|
||||
print(f"Initial Memory: {start_mem:.2f} MB")
|
||||
|
||||
for i in range(iterations):
|
||||
# Repeated PDF open/close, cache operations
|
||||
doc = pdfengine.PdfDocument.load_from_file(pdf_file)
|
||||
fonts = doc.get_fonts(0, -1)
|
||||
|
||||
page = doc.get_page(0)
|
||||
text = page.extract_text()
|
||||
glyphs = page.extract_text_with_bounds()
|
||||
|
||||
# Explicitly delete references
|
||||
del glyphs
|
||||
del text
|
||||
del page
|
||||
del fonts
|
||||
del doc
|
||||
|
||||
if (i + 1) % 200 == 0:
|
||||
gc.collect()
|
||||
curr_mem = get_memory_mb()
|
||||
print(f"Iteration {i + 1}: {curr_mem:.2f} MB (Delta: {curr_mem - start_mem:.2f} MB)")
|
||||
|
||||
gc.collect()
|
||||
end_mem = get_memory_mb()
|
||||
print(f"Final Memory: {end_mem:.2f} MB")
|
||||
delta = end_mem - start_mem
|
||||
print(f"Total Delta: {delta:.2f} MB")
|
||||
|
||||
if delta > 5.0:
|
||||
print("WARNING: Possible memory leak detected!")
|
||||
else:
|
||||
print("SUCCESS: Memory usage is stable. No leaks detected.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
validate_memory()
|
||||
Reference in New Issue
Block a user