u1234x1234 / pynanoflann

Unofficial python wrapper to the nanoflann k-d tree
BSD 2-Clause "Simplified" License
33 stars 8 forks source link

Memory leak #2

Closed juldaani closed 3 years ago

juldaani commented 3 years ago

Hey,

Thanks for the very good library, it is quite fast (fastest python implementation I've found so far). Unfortunately it seems that there is a memory leak somewhere.

If I run the following code memory usage keeps slowly increasing:

import pynanoflann
import numpy as np

for i in range(100):
    print(i)

    nn_search = pynanoflann.KDTree(n_neighbors=1, metric='L2', leaf_size=20)    
    nn_search.fit(np.random.rand(10000000,3))
    _, nn_idx = nn_search.kneighbors(np.random.rand(1000,3))

    del nn_search, nn_idx

I'm using version 0.0.1 of pynanoflann. The problem limits the usability of the library since I've to create new kdtree in each loop iteration and in the end I'll run out of memory.

Best regards Juho

u1234x1234 commented 3 years ago

Hello Juho,

Sorry for the caused problems. I've reproduced your example and made a fix. Outputs of /usr/bin/time: For 5 iterations:

User time (seconds): 36.14
Maximum resident set size (kbytes): 458040

For 100 iterations:

User time (seconds): 726.69
Maximum resident set size (kbytes): 458308

So I guess the problem should go away now. Could you please try the new version:

pip install git+https://github.com/u1234x1234/pynanoflann.git@0.0.3

Best, Dmitrii

juldaani commented 3 years ago

Hey Dmitrii,

Now it works like a charm. Lot of thanks for the fast response. I really appreciate that people are creating and maintaining this kind of fast and computationally efficient libraries for python.

Best regards Juho

u1234x1234 commented 3 years ago

Glad it helped you. I'm closing the issue.