[Biopython-dev] Bio.PDB.KDTree test for memory leak

Peter biopython at maubp.freeserve.co.uk
Fri Feb 12 06:10:13 UTC 2010


On Thu, Feb 11, 2010 at 12:31 PM, Kristian Rother <krother at rubor.de> wrote:
>
> Hi,
>
> I've encountered a problem with running KDTree: it leaks memory.
> The code below fills 1GB memory within a minute.
>
> Running the GC doesn't help (it slows the process down, but only because
> the GC is much slower than KDTree.

You mean something like this?

import gc
from Bio.KDTree.KDTree import *
from numpy.random import random

nr_points=1000
dim=3
bucket_size=10
coords=(200*random((nr_points, dim)))

while True:
   kdtree=KDTree(dim, bucket_size)
   kdtree.set_coords(coords)
   del kdtree #explicitly tell Python it can GC this object
   gc.collect() #force Python to run GC

I agree, this does seem to gradually consume more and more RAM.
Could you open a bug on bugzilla to track this please?

> I think the problem might be in the C code. I'd like to get this bug
> sorted out, but I'm not very good in C. Is there anyone around who
> I could check ideas with?

Have you ever used valgrind on a C tool? I'm not sure if it is easy
to use via Python, but it is my tool of choice for checking memory
leaks in C.

Peter



More information about the Biopython-dev mailing list