Skip to content

fix: delete the local references created for received data channel messages - #272

Merged
devopvoid merged 1 commit into
devopvoid:mainfrom
SendableMetatype:fix/data-channel-message-refs
Sep 7, 2026
Merged

fix: delete the local references created for received data channel messages#272
devopvoid merged 1 commit into
devopvoid:mainfrom
SendableMetatype:fix/data-channel-message-refs

Conversation

@SendableMetatype

Copy link
Copy Markdown
Contributor

RTCDataChannelObserver::OnMessage runs on a libwebrtc thread that stays attached to the JVM for its whole life, so JNI local references it creates are never reclaimed on their own. It created two per received message and deleted neither: the direct ByteBuffer wrapping the payload, and the RTCDataChannelBuffer, which was handed to the callback with release() so the wrapper never deleted it. Every received message therefore leaked both objects until the process exited, which is the growth reported in #265. The buffer factory now deletes the ByteBuffer reference once the RTCDataChannelBuffer holds it, and the observer passes the buffer with get() so the wrapper deletes it after the callback returns, as every other callback in the project does.

Fixes #265

…ssages

RTCDataChannelObserver::OnMessage runs on a libwebrtc thread that stays
attached to the JVM for its whole life, so JNI local references it
creates are never reclaimed on their own. It created two per message and
deleted neither: the direct ByteBuffer wrapping the payload, and the
RTCDataChannelBuffer, which was handed to the callback with release()
so the wrapper never deleted it. Every received message therefore leaked
both objects until the process exited.

The buffer factory now deletes the ByteBuffer reference once the
RTCDataChannelBuffer holds it, and the observer passes the buffer with
get() so the wrapper deletes it after the callback returns, as every
other callback in the project does.
@devopvoid
devopvoid merged commit 40e538b into devopvoid:main Sep 7, 2026
11 checks passed
@SendableMetatype
SendableMetatype deleted the fix/data-channel-message-refs branch September 7, 2026 10:42
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 in RTCDataChannelObserver::OnMessage

2 participants