Thanks, I see that Sections really are deleted when no more python references exist.
Is there an object on which I can call dir() to list all NetCon objects
Read about allobjects in the Programmer's Reference.
This is very close to what I need, but it only prints the results instead of returning them.
There is no local namespace I can introspect to find all NetCon objects
Seems like the wrong way to do it.
For each class X of which you want to keep track, append each instance to a list when you create it. These lists become the manifest of what is in the model.
I disagree--I can keep a list of NEURON objects that I create, but this list will quickly become out of sync with the actual set of objects that NEURON knows about. In particular, it is likely that removing an item from the list will not result in removal from NEURON because there are likely to be extra references to these objects elsewhere in the program. Especially for large programs, leaked references can be very difficult to track and manage. So it seems that I have no way to explicitly remove objects from NEURON, and no way to programmatically ask NEURON what objects it knows about. I've tried using gc.get_objects() to search for leaked objects, but NEURON objects do not appear in this list.
The only solution I have come up with to avoid this situation is to write my own set of classes that wrap each NEURON class and that manage private references to the underlying NEURON objects. Alternatively, I can give up on allowing multiple simulation runs per process and instead spawn new processes for each run. I have been trying to avoid that, but then I came across this note:
So is starting one process per simulation really the recommended approach?