eukreign / python-v8

Apache License 2.0
12 stars 6 forks source link

Memory leak with evaluating pure JS #26

Open eukreign opened 10 years ago

eukreign commented 10 years ago

From alexan...@bekbulatov.ru on April 09, 2014 08:48:46

What steps will reproduce the problem? import os, gc import PyV8 def get_mem(): a = os.popen('ps -p %d -o %s | tail -1' % (os.getpid(),"vsize,rss,pcpu")).read() a = a.split() return (int(a[0]), int(a[1]))

def main(): js_code = 'function hello(name) { return "Hello " + name + " from Javascript"; }'

for i in xrange(10**5):
    with PyV8.JSContext() as ctx:
        ctx.eval(js_code)
        PyV8.JSEngine.collect()
    if i % 10000:
        print get_mem()

if name == "main": main() What is the expected output? What do you see instead? I watch increasing consuming memory. It's not so evident on small JS, but it grows quickly with 300Kb JS file What version of the product are you using? On what operating system? Centos 6.4, PyV8 1.0 Please provide any additional information below. PyV8.JSEngine.collect() doesn't seem to influence on memory consuming

Original issue: http://code.google.com/p/pyv8/issues/detail?id=230

eukreign commented 10 years ago

From alexan...@bekbulatov.ru on April 09, 2014 06:22:37

This one would be more correct example

for i in xrange(10**5):
    with PyV8.JSContext() as ctx:
        ctx.eval(js_code)
    if i % 10000:
        PyV8.JSEngine.collect()
        gc.collect()
        print get_mem()
eukreign commented 10 years ago

From alexan...@bekbulatov.ru on April 09, 2014 23:40:06

  1. Test 1: Eval empty string

js_code = ''

(741580, 16600) ... (741580, 16600)

Looks ok!

  1. Test 2: Eval small js code

js_code = 'function hello(name) { return "Hello " + name + " from Javascript"; }'

(741576, 16596) (741580, 16636) (741580, 16644) ... (747648, 22080)

Then I stopped. It leaks but not so much

  1. Test 3: Eval 300Kb js file

js_code = open('bem/touch.bundles/rubric/rubric.xml.js', 'r').read().decode('utf-8')

(744060, 20436) (745880, 21796) (746904, 22272) ... (1148336, 311196) (1148336, 311556)

This is huge leak. Test finished with

PyV8.JSError: JSError: Allocation failed - process out of memory

Thank you in advance for any help.