pydocx icon indicating copy to clipboard operation
pydocx copied to clipboard

Encountering a memory leak when call PyDocX.to_html?

Open sunglowrise opened this issue 4 years ago • 3 comments

Hi! Encountering a memory leak when call PyDocX.to_html, is not the right way to use it ?

test example:

# python3.6 
# PyDocX == 0.9.10
def test_to_html():
    tracemalloc.start()
    snapshot1 = tracemalloc.take_snapshot()

    for i in range(10):
        with open("/tmp/test.docx", "rb") as f:
            html = PyDocX.to_html(f)
            print(html)

    snapshot2 = tracemalloc.take_snapshot()
    top_stats = snapshot2.compare_to(snapshot1, "lineno")
    for stat in top_stats:
        print(stat)

sunglowrise avatar Oct 14 '20 07:10 sunglowrise

We seem to have the same issue when repeatedly calling .to_hml, memory consumption keeps rising by ~ 30MB increments.

AlexandreRozier avatar Aug 31 '22 08:08 AlexandreRozier

I seem to have the same issue and it caused the container to crash on restart

xxxpppfff avatar Apr 21 '23 02:04 xxxpppfff

Hi! Encountering a memory leak when call PyDocX.to_html, is not the right way to use it ?

test example:

# python3.6 
# PyDocX == 0.9.10
def test_to_html():
    tracemalloc.start()
    snapshot1 = tracemalloc.take_snapshot()

    for i in range(10):
        with open("/tmp/test.docx", "rb") as f:
            html = PyDocX.to_html(f)
            print(html)

    snapshot2 = tracemalloc.take_snapshot()
    top_stats = snapshot2.compare_to(snapshot1, "lineno")
    for stat in top_stats:
        print(stat)

I'm supplying the file path to to_html and didn't see memory leaks (please take this with a grain of salt because I don't know how to properly analyze the snapshots).

Also you may want to use tracemalloc.stop().

henrymcl avatar Feb 20 '24 06:02 henrymcl