fengzhao / fengzhao/pyv8

Garbage Collector not working

Open
#229 8 comments 0 reactions 0 assignees View on GitHub
auto-migrated Priority-Medium Type-Defect
Dominant language
Python
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Description

```
*What steps will reproduce the problem?*
1. Run the attached file minimal.py on a system with PyV8.
2. See the output - in my case there's ~300 MB of additional memory used after
every test run.

{{{
class TestMemoryWithJSContext(unittest.TestCase):
def test_python_memory_management(self):
def inner():
with JSContext() as ctx:
log_memory_usage("before empty evals")
for index1 in range(1000):
for index2 in range(10000):
ctx.eval("")
log_memory_usage("after empty evals")
JSEngine.collect()
log_memory_usage("before JSContext memory tests")
inner()
JSEngine.collect()
gc.collect()
JSEngine.collect()
gc.collect()
log_memory_usage("after JSContext memory tests and gc")
print "Py gc.garbage:", gc.garbage

class CardEngineTestSuite(unittest.TestSuite):
def __init__(self):
super(CardEngineTestSuite, self).__init__()
self.addTests(unittest.TestLoader().loadTestsFromTestCase(TestPython))
self.addTests(unittest.TestLoader().loadTestsFromTestCase(TestMemoryWithJSContext))
}}}

*What is the expected output?*
I'd like to see a way to actually collect garbage in PyV8. Nothing works for me
so far. As you can see, of 320MB of garbage that's generated (noteworthy: only
using empty evals `ctx.eval("")`), only 20MB gets collected, even after 2
consecutive calls of JSEngine.collect and gc.collect, both when ctx is
reachable and when it's not reachable anymore. Note that the attached file
includes a test of the Python garbage collector that appears to be working
correctly when not interacting with PyV8.

*What do you see instead?*
>> python minimal.py
...
python minimal.py
...
.2014-03-28 21:41:34,198 before JSContext memory tests process 110 now uses
14.1 MB resident
2014-03-28 21:41:34,199 before empty evals process 110 now uses 14.4 MB resident
2014-03-28 21:41:55,513 after empty evals process 110 now uses 348.8 MB resident
2014-03-28 21:41:56,926 after JSContext memory tests and gc process 110 now
uses 322.3 MB resident
Py gc.garbage: []
.
----------------------------------------------------------------------
Ran 2 tests in 26.838s

OK
...
.2014-03-28 21:42:01,103 before JSContext memory tests process 110 now uses
322.5 MB resident
2014-03-28 21:42:01,104 before empty evals process 110 now uses 322.5 MB
resident
2014-03-28 21:42:25,714 after empty evals process 110 now uses 636.5 MB resident
2014-03-28 21:42:28,459 after JSContext memory tests and gc process 110 now
uses 629.3 MB resident
Py gc.garbage: []
.
----------------------------------------------------------------------
Ran 2 tests in 31.532s

OK

*What version of the product are you using? On what operating system?*
PyV8 revision 557
built using setup.py and v8 revision 19632
Ubuntu 12.04, running inside a Docker container.

```

Original issue reported on code.google.com by `mmueller...@gmail.com` on 28 Mar 2014 at 9:54

Attachments:
- [minimal.py](https://storage.googleapis.com/google-code-attachments/pyv8/issue-229/comment-0/minimal.py)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.