Skip to content

Prevent ref from pushing objects to its internal array#385

Merged
minggangw merged 1 commit intoRobotWebTools:developfrom
minggangw:fix-issue-382
Jul 23, 2018
Merged

Prevent ref from pushing objects to its internal array#385
minggangw merged 1 commit intoRobotWebTools:developfrom
minggangw:fix-issue-382

Conversation

@minggangw
Copy link
Copy Markdown
Member

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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory leak when deserializing string members

1 participant