Skip to content

fix: dispose native objects once and keep them while a call still uses them - #520

Merged
devopvoid merged 1 commit into
mainfrom
fix/native-dispose-races
Nov 2, 2026
Merged

devopvoid merged 1 commit into
mainfrom
fix/native-dispose-races

Conversation

@devopvoid

Copy link
Copy Markdown
Owner
  • dispose() and close() take the native handle atomically, so repeated or concurrent calls do nothing instead of freeing the object twice or throwing.
  • Native methods hold the handle while they run; an object disposed meanwhile on another thread is freed by the last call that still uses it, without anyone waiting, so close() from an observer callback stays safe.
  • Methods of a disposed object throw an IllegalStateException naming its class (e.g. "RTCPeerConnection is closed") instead of NullPointerException("Object handle is null").
  • The nativeHandle field ID is cached instead of looked up on every call.

…s them

Dispose and close take the handle atomically, so repeated or concurrent calls do nothing, and release the native object only once no native method on another thread still uses it. Methods of a disposed object throw an IllegalStateException naming its class.
@devopvoid
devopvoid merged commit e9bb3ee into main Nov 2, 2026
39 of 40 checks passed
@devopvoid
devopvoid deleted the fix/native-dispose-races branch November 2, 2026 19:52
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.

1 participant