Closed edovanveen closed 1 year ago
We should only be telling NEURON to delete the object if its reference count goes to 0.
Presumably deleting it in MATLAB should simply decrement its reference count by 1.
Removing clibRelease
was causing crashes on reruns, so I put it back for now; it is only run if the MATLAB Object owns the NEURON Object (see Object.objowner
and Object.delete()
in PR #47). In the future it is advisable to look at this issue again and see if it also works to simply decrease the refcount
.
I got rid of the objowner
nonsense; currently deleting an Object looks like the code below. I still have to do clibRelease
because otherwise some examples crash if run in succession.
function delete(self)
% Decrease refcount by 1; if refcount is 0, release the C++ Object.
% delete()
self.obj.refcount = self.obj.refcount - 1;
% We need to do this, or else we get crashes.
if self.obj.refcount == 0
clib.neuron.hoc_obj_unref(self.obj);
clibRelease(self.obj);
end
The user currently has to explicitly delete any NEURON Objects by running
Object.delete_nrn_obj()
in MATLAB. If this method were namedObject.delete()
it would lead to unexpected behaviour, such as deleting a vector upon callingVector.append()
without catching the output.Instead we could keep track of whether the MATLAB Object is the owner of the NEURON Object, and if so, run
Object.delete_nrn_obj()
uponObject.delete()
.