Skip to content

Commit b048960

Browse files
jrobichaudhobu
authored andcommitted
Fix memory leak (#45)
* Fix memory leak * Expose bug with reference counting * Release the temporary arrays
1 parent 3d94698 commit b048960

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

pdal/libpdalpython.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ cdef class PyPipeline:
155155
a = ptr#.get()
156156
o = a.getPythonArray()
157157
output.append(<object>o)
158+
del ptr
158159
inc(it)
159160
return output
160161

test/test_pipeline.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
import unittest
23
import pdal
34
import os
@@ -191,6 +192,37 @@ def test_read_arrays(self):
191192
self.assertEqual(count, 2)
192193
self.assertEqual(len(arrays), 1)
193194

195+
def test_reference_counting(self):
196+
"""Can we read and filter data from a list of arrays to PDAL"""
197+
if Version(pdal.info.version) < Version("1.8"):
198+
return True
199+
200+
# just some dummy data
201+
x_vals = [1.0, 2.0, 3.0, 4.0, 5.0]
202+
y_vals = [6.0, 7.0, 8.0, 9.0, 10.0]
203+
z_vals = [1.5, 3.5, 5.5, 7.5, 9.5]
204+
test_data = np.array(
205+
[(x, y, z) for x, y, z in zip(x_vals, y_vals, z_vals)],
206+
dtype=[("X", np.float), ("Y", np.float), ("Z", np.float)],
207+
)
208+
209+
pipeline = """
210+
{
211+
"pipeline": [
212+
{
213+
"type":"filters.range",
214+
"limits":"X[2.5:4.5]"
215+
}
216+
]
217+
}
218+
"""
219+
220+
p = pdal.Pipeline(pipeline, arrays=[test_data])
221+
p.loglevel = 8
222+
count = p.execute()
223+
self.assertEqual(count, 2)
224+
self.assertEqual(1, sys.getrefcount(p.arrays[0]), "Reference count should only be 1 in this case")
225+
194226

195227
class TestDimensions(PDALTest):
196228
def test_fetch_dimensions(self):

0 commit comments

Comments
 (0)