wojtossfm / pyv8

Automatically exported from code.google.com/p/pyv8

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Strange memory leak on assignment

GoogleCodeExporter opened this issue · comments

We notice a memory leak when tried to implement the rendering with the 
following logic:

import PyV8


SCRIPT_JS = """
    function build() { return {}; }
    function render(val) { return ""; }
"""

# create JSContext and load JavaScript functions
with PyV8.JSContext() as ctx:
    ctx.eval(SCRIPT_JS)

def render():
    with ctx:
        # the following line causes a memory leak
        ctx.locals.data = ctx.eval(build();')
        return ctx.eval('render(data);')

# render many many times
for i in range(0, 1000000):
    render()


What steps will reproduce the problem?

Use assignment like:

        ctx.locals.data = ctx.eval('build();')

What is the expected output? What do you see instead?

I expect that the memory will be cleared.

What version of the product are you using? On what operating system?

pyv8-1.0+svn472.13440


Original issue reported on code.google.com by e.generalov on 21 Jan 2013 at 10:21

Original comment by flier...@gmail.com on 1 Feb 2013 at 1:59

  • Changed state: Accepted
  • Added labels: OpSys-All
The root cause is PyV8 try to trace every object in context with a living 
object mapping, but if you leave a context with some living objects, the 
mapping will not be free. So, just force free all the objects in the mapping.

Please verify the issue with SVN trunk code after r479, thanks

Original comment by flier...@gmail.com on 3 Feb 2013 at 3:39

  • Changed state: Fixed