-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modernize memory management in RxD. #2512
Comments
Broadly, I support this, although the |
For
because However, if we wanted to change the implementation of The way non-trivial classes work, is that they need to be initialized:
both ensure that Note that this is transient. If a class contains a member which is non-trivial, then the struct itself will be non-trivial. Summary: I would strongly advocate to |
Looking at
grids.{h,c}pp
we find lots of code:nrn/src/nrnpython/grids.h
Lines 99 to 107 in f74ec59
nrn/src/nrnpython/grids.h
Lines 119 to 123 in f74ec59
and allocation in a ctor:
nrn/src/nrnpython/grids.cpp
Lines 254 to 257 in f74ec59
or in random functions:
nrn/src/nrnpython/grids.cpp
Lines 836 to 837 in f74ec59
with deallocation redundantly scattered across multiple dtors:
nrn/src/nrnpython/grids.cpp
Lines 1244 to 1248 in f74ec59
nrn/src/nrnpython/grids.cpp
Lines 1739 to 1744 in f74ec59
Note, that
state_z
is only deallocated in one of the two, creating additional complexity. (There's a comment claiming this is intended.)There are multiple issues here:
malloc
allocates N bytes of memory. Often it'll be zeroed out; but there's no guarantee. What it doesn't do is initialize the values correctly. This matters for non-trivial types, such as anstd::vector
. Non-trivial types often allocate memory; and to avoid leaking memory they also deallocate memory. If the pointer is initially put into a random state this will lead to either dereferencing that random address; or attempting to deallocate it.delete
) differently than multiple elements (delete[]
).The text was updated successfully, but these errors were encountered: