ironm73 / pyv8

Automatically exported from code.google.com/p/pyv8
0 stars 0 forks source link

context.eval memory leak #128

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
latest PyV8 and V8 from svn trunk

What is reason memory leak in:

import os
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():
    ctx = PyV8.JSContext()
        for i in xrange(10**6):
            with ctx:
                res = ctx.eval("%i" % i)
            if i % 1000 == 0:
                print get_mem()

if __name__ == "__main__":
    main()

Original issue reported on code.google.com by driverx....@gmail.com on 24 Jul 2012 at 12:18

GoogleCodeExporter commented 8 years ago
I will check it later

Original comment by flier...@gmail.com on 25 Jul 2012 at 2:56

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Yep, same problem here. Very disturbing in production environment. 

Xiaohai,  if you can have a look quickly it would be awesome ;-) Thanks.

Original comment by on.cel...@gmail.com on 20 Aug 2012 at 11:57

GoogleCodeExporter commented 8 years ago
The root cause is that you pass too many objects to Javascript, but v8 doesn't 
have chance to GC those, please add a PyV8.JSEngine.collect() after get_mem() 
call, which will force v8 collect all the dead objects.

Original comment by flier...@gmail.com on 20 Aug 2012 at 1:58

GoogleCodeExporter commented 8 years ago
import PyV8

def main():
    ctx = PyV8.JSContext()
    for i in xrange(10**6):
        with ctx:
            res = ctx.eval("%i" % i)
            del res
            res = None

        if i % 1000 == 0:
            PyV8.JSEngine.collect()

if __name__ == "__main__":
    main()

Original comment by flier...@gmail.com on 20 Aug 2012 at 2:00