Prevent ref from pushing objects to its internal array#385
Merged
minggangw merged 1 commit intoRobotWebTools:developfrom Jul 23, 2018
Merged
Prevent ref from pushing objects to its internal array#385minggangw merged 1 commit intoRobotWebTools:developfrom
minggangw merged 1 commit intoRobotWebTools:developfrom
Conversation
At the early stage of rclnodejs testing, we noticed that if the application continuously ran for a long time(more than 24 hours), the memory usage raised accordingly, see RobotWebTools#175. Because the rclnodejs has to free the memory allocated by rcl library, we suspected some block of memory may be missed out to be freed. Recently @martins-mozeiko reported this issue again, what's more he did a lot of investigation about this issue and found that the root cause of it finally. As we use ref to create the memory layout of a struct(message) on native side, and the ref pushes the value which is to be assigned, to its internal array which prevents it from being garbage collected. Thus if we create a subscription to receive a topic many times, which means we have to assign the value to the ref object frequently. The result is that the ref object will hold all the values which consumes memory a lot. This patch resolves this problem by creating a new ref object each time the subscription/client/service receives a topic/response/request. This will guarantee that the ref object will not reference many handles. Fix RobotWebTools#381
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
At the early stage of rclnodejs testing, we noticed that if the
application continuously ran for a long time(more than 24 hours),
the memory usage raised accordingly, see #175. Because the rclnodejs has
to free the memory allocated by rcl library, we suspected some block of
memory may be missed out to be freed.
Recently @martins-mozeiko reported this issue again, what's more he did
a lot of investigation about this issue and found that the root cause of
it finally. As we use ref to create the memory layout of a struct(message)
on native side, and the ref pushes the value which is to be assigned, to
its internal array which prevents it from being garbage collected. Thus
if we create a subscription to receive a topic many times, which means
we have to assign the value to the ref object frequently. The result is
that the ref object will hold all the values which consumes memory a
lot.
This patch resolves this problem by creating a new ref object each time
the subscription/client/service receives a topic/response/request. This
will guarantee that the ref object will not reference many handles.
Fix #381