[Community] Possible Rtree 0.4.1 memory leak, Does spatialindex do query caching?

Chris Adams lithium_eadgbe at hotmail.com
Sun Jan 4 01:08:15 EET 2009


I fixed the problem, it deem seem to be a memory leak

in rtree/wrapper.cc, in the PyListVisitor class, I changed the visitData function to the following:

    void visitData(const IData & d)
    {
        PyObject * ob = PyLong_FromLongLong(d.getIdentifier());
        PyList_Append(ids, ob);
        Py_DECREF(ob);
    }

after rebuilding this, I ran the test described in the previous post, and the memory leak was fixed. I then tested my own application as a correctness test, and although the running time increased slightly, the output was correct.

- Chris

From: lithium_eadgbe at hotmail.com
To: community at lists.gispython.org
Date: Sat, 3 Jan 2009 16:51:19 -0400
Subject: [Community] Possible Rtree 0.4.1 memory leak, Does spatialindex do query caching?








Running the following python script, which uses Rtree 0.4.1, which uses spatialindex, after the index is built the repeated queries cause the memory usage to increase by megabytes a second. This is not a python garbage collection problem, you can see, the ref count of zxy, and x (results) are both equal (2), which indicates one reference for the variable, and one reference for the parameter to the getrefcount function.

from rtree import Rtree
import sys
def y(index):
    zxy = [ 1, 2, 3, 4 ]
    print "zyx: %d"%(sys.getrefcount(zxy))
    x = index.intersection((0.25, 0.25, 0.75, 0.75))
    print "x: %d"%(sys.getrefcount(x))
    print "x: %d"%(sys.getrefcount(x))
    del x[:]
    del x

index = Rtree()
for i in range(0, 50000):
    index.add(i, (0, 0, 1, 1))
while 1:
    y(index)

Thanks,

- Chris
Share your holiday memories for free with Windows LiveT Photos. Get started now.
_________________________________________________________________
Drag n’ drop—Get easy photo sharing with Windows Live™ Photos.
http://www.microsoft.com/windows/windowslive/photos.aspx
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gispython.org/pipermail/community/attachments/20090103/bb4cf6ff/attachment.htm>


More information about the Community mailing list