Closed edovanveen closed 1 year ago
I think the underlying issue is that we need to increment the returned object's refcount
in +neuron/+stack/hoc_pop.m
's hoc_pop
. I think the reason we didn't run into this before was that the refcount
for things that already existed was non-zero and so they weren't getting garbage collected on the C-side. Incrementing refcount
on return may also fix the underlying issue that led to #68 where MATLAB garbage collection was causing objects to go away when they shouldn't (because the refcount
wasn't right).
For an example with Vector.c()
, see https://github.com/mcdougallab/neuron-c-api-demos/blob/main/vector-dot-c/vector-dot-c.cpp The main function of interest is: call_object_method_that_returns_object
In particular, commenting out the new_ob_ptr->refcount++;
line will lead to the Vector getting garbage collected and not being useable for printf
.
Fixed in PR #47
How do we deal with methods that return new objects? For example
Vector.c()
and (probably)ParallelContext.gid_connect(i, cell)
.