tbodt/v8py

v8py context object memory leak

byronpatrick22 opened this issue · 4 comments

Excessive memory consumption with many v8py.Context objects created.

from memory_profiler import profile

@profile
def local_v8py():
    import v8py
    v8_context = v8py.Context()
    del v8_context

def main():
    for _ in range(1000):
        local_v8py()

main()

$ python -m memory_profiler v8py_test.py

Memory profile output:

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     28.2 MiB     28.2 MiB   @profile
 4                             def local_v8py():
 5     39.0 MiB     10.8 MiB       import v8py
 6     40.1 MiB      1.2 MiB       v8_context = v8py.Context()
 7     40.1 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     40.1 MiB     40.1 MiB   @profile
 4                             def local_v8py():
 5     40.1 MiB      0.0 MiB       import v8py
 6     40.4 MiB      0.3 MiB       v8_context = v8py.Context()
 7     40.4 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     40.4 MiB     40.4 MiB   @profile
 4                             def local_v8py():
 5     40.4 MiB      0.0 MiB       import v8py
 6     40.4 MiB      0.0 MiB       v8_context = v8py.Context()
 7     40.4 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     40.4 MiB     40.4 MiB   @profile
 4                             def local_v8py():
 5     40.4 MiB      0.0 MiB       import v8py
 6     40.7 MiB      0.3 MiB       v8_context = v8py.Context()
 7     40.7 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     40.7 MiB     40.7 MiB   @profile
 4                             def local_v8py():
 5     40.7 MiB      0.0 MiB       import v8py
 6     40.9 MiB      0.3 MiB       v8_context = v8py.Context()
 7     40.9 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     40.9 MiB     40.9 MiB   @profile
 4                             def local_v8py():
 5     40.9 MiB      0.0 MiB       import v8py
 6     41.2 MiB      0.3 MiB       v8_context = v8py.Context()
 7     41.2 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     41.2 MiB     41.2 MiB   @profile
 4                             def local_v8py():
 5     41.2 MiB      0.0 MiB       import v8py
 6     41.4 MiB      0.3 MiB       v8_context = v8py.Context()
 7     41.4 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     41.4 MiB     41.4 MiB   @profile
 4                             def local_v8py():
 5     41.4 MiB      0.0 MiB       import v8py
 6     41.4 MiB      0.0 MiB       v8_context = v8py.Context()
 7     41.4 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     41.4 MiB     41.4 MiB   @profile
 4                             def local_v8py():
 5     41.4 MiB      0.0 MiB       import v8py
 6     41.7 MiB      0.3 MiB       v8_context = v8py.Context()
 7     41.7 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     41.7 MiB     41.7 MiB   @profile
 4                             def local_v8py():
 5     41.7 MiB      0.0 MiB       import v8py
 6     41.9 MiB      0.3 MiB       v8_context = v8py.Context()
 7     41.9 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     41.9 MiB     41.9 MiB   @profile
 4                             def local_v8py():
 5     41.9 MiB      0.0 MiB       import v8py
 6     42.2 MiB      0.3 MiB       v8_context = v8py.Context()
 7     42.2 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     42.2 MiB     42.2 MiB   @profile
 4                             def local_v8py():
 5     42.2 MiB      0.0 MiB       import v8py
 6     42.5 MiB      0.3 MiB       v8_context = v8py.Context()
 7     42.5 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     42.5 MiB     42.5 MiB   @profile
 4                             def local_v8py():
 5     42.5 MiB      0.0 MiB       import v8py
 6     42.5 MiB      0.0 MiB       v8_context = v8py.Context()
 7     42.5 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     42.5 MiB     42.5 MiB   @profile
 4                             def local_v8py():
 5     42.5 MiB      0.0 MiB       import v8py
 6     42.7 MiB      0.3 MiB       v8_context = v8py.Context()
 7     42.7 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     42.7 MiB     42.7 MiB   @profile
 4                             def local_v8py():
 5     42.7 MiB      0.0 MiB       import v8py
 6     43.0 MiB      0.3 MiB       v8_context = v8py.Context()
 7     43.0 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     43.0 MiB     43.0 MiB   @profile
 4                             def local_v8py():
 5     43.0 MiB      0.0 MiB       import v8py
 6     43.2 MiB      0.3 MiB       v8_context = v8py.Context()
 7     43.2 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     43.2 MiB     43.2 MiB   @profile
 4                             def local_v8py():
 5     43.2 MiB      0.0 MiB       import v8py
 6     43.2 MiB      0.0 MiB       v8_context = v8py.Context()
 7     43.2 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     43.2 MiB     43.2 MiB   @profile
 4                             def local_v8py():
 5     43.2 MiB      0.0 MiB       import v8py
 6     43.5 MiB      0.3 MiB       v8_context = v8py.Context()
 7     43.5 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     43.5 MiB     43.5 MiB   @profile
 4                             def local_v8py():
 5     43.5 MiB      0.0 MiB       import v8py
 6     43.7 MiB      0.3 MiB       v8_context = v8py.Context()
 7     43.7 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     43.7 MiB     43.7 MiB   @profile
 4                             def local_v8py():
 5     43.7 MiB      0.0 MiB       import v8py
 6     44.0 MiB      0.3 MiB       v8_context = v8py.Context()
 7     44.0 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     44.0 MiB     44.0 MiB   @profile
 4                             def local_v8py():
 5     44.0 MiB      0.0 MiB       import v8py
 6     44.0 MiB      0.0 MiB       v8_context = v8py.Context()
 7     44.0 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     44.0 MiB     44.0 MiB   @profile
 4                             def local_v8py():
 5     44.0 MiB      0.0 MiB       import v8py
 6     44.3 MiB      0.3 MiB       v8_context = v8py.Context()
 7     44.3 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     44.3 MiB     44.3 MiB   @profile
 4                             def local_v8py():
 5     44.3 MiB      0.0 MiB       import v8py
 6     44.5 MiB      0.3 MiB       v8_context = v8py.Context()
 7     44.5 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     44.5 MiB     44.5 MiB   @profile
 4                             def local_v8py():
 5     44.5 MiB      0.0 MiB       import v8py
 6     44.8 MiB      0.3 MiB       v8_context = v8py.Context()
 7     44.8 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     44.8 MiB     44.8 MiB   @profile
 4                             def local_v8py():
 5     44.8 MiB      0.0 MiB       import v8py
 6     45.0 MiB      0.3 MiB       v8_context = v8py.Context()
 7     45.0 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     45.0 MiB     45.0 MiB   @profile
 4                             def local_v8py():
 5     45.0 MiB      0.0 MiB       import v8py
 6     45.0 MiB      0.0 MiB       v8_context = v8py.Context()
 7     45.0 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     45.0 MiB     45.0 MiB   @profile
 4                             def local_v8py():
 5     45.0 MiB      0.0 MiB       import v8py
 6     45.3 MiB      0.3 MiB       v8_context = v8py.Context()
 7     45.3 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     45.3 MiB     45.3 MiB   @profile
 4                             def local_v8py():
 5     45.3 MiB      0.0 MiB       import v8py
 6     45.5 MiB      0.3 MiB       v8_context = v8py.Context()
 7     45.5 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     45.5 MiB     45.5 MiB   @profile
 4                             def local_v8py():
 5     45.5 MiB      0.0 MiB       import v8py
 6     45.8 MiB      0.3 MiB       v8_context = v8py.Context()
 7     45.8 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     45.8 MiB     45.8 MiB   @profile
 4                             def local_v8py():
 5     45.8 MiB      0.0 MiB       import v8py
 6     46.1 MiB      0.3 MiB       v8_context = v8py.Context()
 7     46.1 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     46.1 MiB     46.1 MiB   @profile
 4                             def local_v8py():
 5     46.1 MiB      0.0 MiB       import v8py
 6     46.1 MiB      0.0 MiB       v8_context = v8py.Context()
 7     46.1 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     46.1 MiB     46.1 MiB   @profile
 4                             def local_v8py():
 5     46.1 MiB      0.0 MiB       import v8py
 6     46.3 MiB      0.3 MiB       v8_context = v8py.Context()
 7     46.3 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     46.3 MiB     46.3 MiB   @profile
 4                             def local_v8py():
 5     46.3 MiB      0.0 MiB       import v8py
 6     46.6 MiB      0.3 MiB       v8_context = v8py.Context()
 7     46.6 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     46.6 MiB     46.6 MiB   @profile
 4                             def local_v8py():
 5     46.6 MiB      0.0 MiB       import v8py
 6     46.8 MiB      0.3 MiB       v8_context = v8py.Context()
 7     46.8 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     46.8 MiB     46.8 MiB   @profile
 4                             def local_v8py():
 5     46.8 MiB      0.0 MiB       import v8py
 6     46.8 MiB      0.0 MiB       v8_context = v8py.Context()
 7     46.8 MiB      0.0 MiB       del v8_context

Filename: ./v8py_test.py

Line # | Mem usage | Increment | Line Contents

 3     46.8 MiB     46.8 MiB   @profile
 4                             def local_v8py():
 5     46.8 MiB      0.0 MiB       import v8py
 6     47.1 MiB      0.3 MiB       v8_context = v8py.Context()
 7     47.1 MiB      0.0 MiB       del v8_context
tbodt commented

I don't really have time to fix this, but I'd look at a PR.

No worries, I'll have a look.

@byronpatrick22 did you figure this out?

tbodt commented

The issue went away after manually running GC as reported in #36, which means it's not actually an issue.