-
Notifications
You must be signed in to change notification settings - Fork 370
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
Fix memory leak with ResetKernel
#2520
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Is there any performance effect of replacing a normal with a smart pointer? |
@heplesser |
Are there any effects on simulation time? I assume that smart pointers take more memory (reference counting needs to happen somewhere) and thus worry that they are cached less effectively, so that neuron access during spike delivery might become less efficient. And since neurons are created in a single place and deleted in a single place, I don't think we really need smart pointers. I think in #2316 we just overlooked the need for destruction when we went away from the memory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can solve this without smart pointers and the performance and memory cost they imply.
I just did a little test, comparing a program filling a vector with 2^10 For more on the implementation in the gcc case, see https://gcc.gnu.org/onlinedocs/libstdc++/manual/memory.html#std.util.memory.shared_ptr. |
Nodes are created with
new
inGenericModel
:nest-simulator/nestkernel/genericmodel.h
Lines 154 to 158 in d7ef15b
Then the node pointers are stored in
memory_
inModel
. However the nodes are never deleted, which leads to a memory leak when callingResetKernel
. With only a few thousand nodes, callingResetKernel
multiple times can add up to hundreds of MB of leaked memory.This PR puts Node pointers in smart pointers within
memory_
, so that the Nodes are automatically deleted when the model is destroyed. The explicit call to the node destructor inNodeManager
is removed because it interferes with the deletion of the nodes at the end ofModel
s lifetime. This fixes #2519. @ChenK19 Can you check if #2512 is fixed by this as well?