pandana icon indicating copy to clipboard operation
pandana copied to clipboard

destroying a network doesn't release memory

Open knaaptime opened this issue 4 years ago • 4 comments

I'm building on pandana in a slightly non-traditional way, where it's common to do aggregation queries on several networks. I may have misunderstood, but I thought one of the major improvements of the last release was that "Network objects can be created and destroyed at the user's pleasure," but I can't seem to do so--or at least, I never get the memory back.

so if i wanted to do agg queries over several networks in a for loop, I need to use a subprocess otherwise I'll run out of memory after a couple iterations

I can del the network or instantiate another on top of the same variable but I never get the memory back until I quit the python process. Any ideas?

knaaptime avatar Jul 12 '19 17:07 knaaptime

While it is true that the changes done in pandana v.0.4 on the network deletion were aimed to solve these use cases, we never got to the point to do full testing on what happens with memory when networks are destroyed.

To be more clear, we release the memory on the C++ side, but given that Python has a garbage collection memory model it is not possible to guarantee that the memory will be collected. Have you tried forcing collection with the gc package?

Of course, these are my preliminary thoughts, without doing much analysis on the code, just remembering what we did for v0.4 months ago. Solving this kind of use cases is very interesting and should allow more uses of the library, but at this point it's difficult to know when this work could be scheduled.

federicofernandez avatar Jul 16 '19 13:07 federicofernandez

thanks a ton for your reply. I haven't tried using gc, so I will give that a shot and report back. Obviously this is not a huge deal since i can always use subprocesses as a workaround, just wanted to make sure I wasn't missing something obvious (like gc!)

thanks again

knaaptime avatar Jul 16 '19 18:07 knaaptime

Excellent. Please let me know what you encounter. I cannot guarantee at this point that the C++ code is 100% correct in terms of memory leaks, but that was the intention of the last update.

And besides that, it would be great if we can force the GC to collect. We had the same issue with a long running python process that we use to validate data, and we end up creating subprocesses because it was too difficult and without guarantees to force the GC.

That said, I'll do a quick check of the C++ code to check there is anything evident to fix.

federicofernandez avatar Jul 16 '19 18:07 federicofernandez

Disregard. Reviewing my example, the networks are deallocated after further inspection.

d-wasserman avatar Jan 18 '22 01:01 d-wasserman