Reference leak when using PointProcess.get_segment()

When Python is the interpreter, what is a good
design for the interface to the basic NEURON

Moderator: hines

Post Reply
Posts: 22
Joined: Mon Jul 07, 2014 1:12 pm

Reference leak when using PointProcess.get_segment()

Post by lcampagn »

This is an issue I ran into while debugging unit tests in pynrn:

Code: Select all

from neuron import h
s = h.Section()
c = h.IClamp(0.5, s)
g = c.get_segment()
del s
del c
del g
print "Sections:", len(list(h.allsec()))
print "IClamps: ", len(list(h.List('IClamp')))
The output looks like:

Code: Select all

Sections: 1
IClamps:  1
It looks like the Section and IClamp are not collected, but where are the leaked references?
I've tried using `gc.collect()` and `sys.exc_clear()`. I also tried using `gc.get_referrers()` to see where the references might be but the lists come back empty, so I assume the leak is internal to NEURON?

Site Admin
Posts: 1598
Joined: Wed May 18, 2005 3:32 pm

Re: Reference leak when using PointProcess.get_segment()

Post by hines »

This is "fixed" in ... baac236c73
The reason "fixed" is in quotes is because the result of your fragment is now

Code: Select all

Sections: 0
IClamps:  1
and the IClamp ref count has not yet become 0 as it is temporarily being held by an internal buffer. One can tickle the system into releasing it by calling a method on any hoc object. e.g.

Code: Select all

I'm afraid I cannot, so far, figure out a way to safely eliminate that internal buffer. (after the h.Vector().size, the buffer holds a reference to the Vector instance).

Post Reply