hines wrote:Deletion of python sections via h.delete_section(sec=pysec) can be implemented but remember that deletion also occurs when the last python reference to the section dissappears as well.
In the typical case, hoc cell templates that construct hoc sections or python cell objects that construct python sections, the section are deleted with the cell is destroyed (though in the
latter case, the sections are destroyed only if there are no references to the section outside the cell object.
I think I finally figured out why I was having such a difficult time with python sections not being destroyed. While learning how to specify models, I've been executing code in .py files, and then creating and investigating variables from an iPython console, and going back and forth between the two. Apparently iPython "keeps alive" an awful lot of references, making it near impossible to destroy hoc objects. If I limit the executed code to a single run of a .py file, then objects can be destroyed more effectively. However you can see how this is awkward for a new user to have to deal with, so a simple solution would be let the user destroy hoc objects manually, since they will likely not encounter any errors from the references that exist in iPython if they will not be calling any of those references.
hines wrote:
With regard to h.allsec(). that really is all the hoc and python sections so I'm not sure I understand what you mean.
I was more requesting a feature than reporting a bug. Since I have been having issues with h.allsec() still containing references to objects that I attempted but failed to destroy from an iPython console, it would be nice if h.allsec() took an argument to limit the sections it reports, as follows:
Code: Select all
from neuron import h
class CellClass(object):
def __init__(self):
self.sec_list = []
cell1 = CellClass()
soma1 = h.Section(name='soma1', cell=cell1)
soma2 = h.Section(name='soma2')
soma3 = h('create soma3')
for s in h.allsec():
print s.name()
<__main__.CellClass object at 0x1114cbf10>.soma1
soma2
soma3
Code: Select all
h.soma3.push()
h.delete_section()
for s in h.allsec():
print s.name()
<__main__.CellClass object at 0x1114cbf10>.soma1
soma2
So it would be nice if now I could use:
Code: Select all
for s in h.allsec(cell=cell1):
print s.name()
to limit the list of reported sections to those attached to cell1:
<__main__.CellClass object at 0x1114cbf10>.soma1
I think the reason why so many other forum posts are about section garbage collection, is that users are using h.allsec() in their code, but getting references to sections that they thought they destroyed. They wouldn't care if they could use h.allsec() to only report sections attached to a cell that is active in the current simulation, even if other sections still exist in the hoc environment which are not being simulated but are still technically referenced.