sebdraven / pyv8

PyV8
0 stars 0 forks source link

Global object is never freed #189

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

Run the following code:

import sys
import weakref

import PyV8

tracks = {} #map weakref id to (weakref, description)
def tracked_deleted(r):
    _, descr = tracks[id(r)]
    print ("Tracked object '%s' just deleted." % (descr,))
    del tracks[id(r)]
def track(o, descr):
    r = weakref.ref(o, tracked_deleted)
    tracks[id(r)] = (r, "%s:%s" % (o.__class__.__name__, descr))
    return o

class Global(object):
    pass

def just_global():
    glob = track(Global(), "global")
    print "Ref count of global:", sys.getrefcount(glob)

def global_with_ctxt():
    glob = track(Global(), "global")
    print "Ref count of global:", sys.getrefcount(glob)
    print "Creating context..."
    ctxt = track(PyV8.JSContext(glob), "JSContext")
    print "Ref count of global:", sys.getrefcount(glob)
    print "setting context to None"
    ctxt = None
    print "Ref count of global:", sys.getrefcount(glob)

just_global()
print "----"
global_with_ctxt()

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

The actual output is this:

Ref count of global: 2
Tracked object 'Global:global' just deleted.
----
Ref count of global: 2
Creating context...
Ref count of global: 3
setting context to None
Tracked object 'JSContext:JSContext' just deleted.
Ref count of global: 3

The global object in the 2nd case is never freed.

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

Python 2.6.6 , PyV8 r443 , Windows 7

Please provide any additional information below.

Original issue reported on code.google.com by csaft...@gmail.com on 18 Jul 2013 at 9:01

GoogleCodeExporter commented 9 years ago
Note: I tested all these latest bugs (185-189) on the latest trunk from svn 
(using "pip install PyV8") and they occur for the latest version as well.

Original comment by csaft...@gmail.com on 19 Jul 2013 at 5:00

GoogleCodeExporter commented 9 years ago
Please verify the fix with SVN trunk code after r527, Thanks

Original comment by flier...@gmail.com on 12 Aug 2013 at 9:43