Below is some code written iteratively with mild resemblance to the DBSCAN algorithm:
rw = 100
for r in range(rw):
neighs = retrieve_neighs(r)
# rest of body
If I rewrite it using recursion, I might write:
rw = 100
def foo(r):
if r < rw:
neighs = retrieve_neighs(r)
# rest of body
foo(r + 1)
foo(0)
I expect retrieve_neighs to return a list (or some collection) of points - this opens up the possibility that an entire file of data could be loaded, right? Is there any recognition that neighs is not used after
foo(r + 1)
and so the memory neighs refers to is freed?
neighsobject once you are done with performing some operation on it. And if your are returning a list then you can create a generator object instead of whole list.