Skip to content
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

[core] fix shared object leakage on android #25995

Merged
merged 3 commits into from
Dec 20, 2023

Conversation

Kudo
Copy link
Contributor

@Kudo Kudo commented Dec 18, 2023

Why

notice the shared objects have never been deallocated

How

  • introduce the JavaScriptWeakObject that is similar to what we had on ios and integrate to SharedObjectRegistry.
  • add a new deallocate method for derived shared object to be notified when it is deallocated.

Test Plan

test repro on https://github.com/ospfranco/expo-sqlite-benchmark

Checklist

@expo-bot expo-bot added bot: suggestions ExpoBot has some suggestions bot: passed checks ExpoBot has nothing to complain about and removed bot: suggestions ExpoBot has some suggestions labels Dec 18, 2023
@Kudo Kudo marked this pull request as ready for review December 18, 2023 16:19
Comment on lines 71 to 72
_weakObject = jsObject;
_weakObjectType = WeakObjectType::NotSupported;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reality speaking, can that happen? We have some form of weak objects on all supported runtimes (JSC, Hermes, V8). Throwing an error rather than masking an unsupported operation is better. Otherwise, we may not notice something missing on new runtime in the future, causing massive leaks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a good question. in fact, on android, jsc supports jsi::WeakObject. it's just ios < 14.5 would go into this NonSupported flow.
on react-native 0.74, meta removed the flag and jsc should support jsi::WeakObject in all cases. maybe we can remove the logic for WeakRefAvailable/NonSupported here and use jsi::WeakObject for everything on android.

when we moved to 0.74, ios could remove the WeakRef code and align with android implementations. does that make sense to you?

ps. i didn't add jsi::WeakObject to v8 yet which i should. maybe it's good to update it in the christmas seasons.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave that as it is. We still want to make that code common, and I'm not a big fan of adding platform ifs. We can remove that logic later when we will be using 0.74.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i somehow changed my mind. since android supports jsi::WeakObject for all cases. i would go a step further to remove the WeakRef fallback code. ultimately on 0.74, ios will do the same removal and we don't need the shared WeakRef fallback code at all.

@Kudo Kudo force-pushed the @kudo/fix-leak-shared-obj-android branch from 003741b to 8f1a23f Compare December 20, 2023 07:14
@Kudo Kudo merged commit 6590dd0 into main Dec 20, 2023
11 checks passed
@Kudo Kudo deleted the @kudo/fix-leak-shared-obj-android branch December 20, 2023 09:09
Kudo added a commit that referenced this pull request Dec 20, 2023
# Why

based on #25995 to integrate the new `deallocate()` in sqlite and fix
the NativeStatementBinding leakage

# How

integrate `deallocate()` from `SharedObject` and cleanup jni data
Kudo added a commit that referenced this pull request Dec 20, 2023
# Why

notice the shared objects have never been deallocated

# How

- introduce the `JavaScriptWeakObject` that is similar to what we had on
ios and integrate to SharedObjectRegistry.
- add a new `deallocate` method for a derived shared object to be notified
when it is deallocated.

# Test Plan

test repro on https://github.com/ospfranco/expo-sqlite-benchmark

(cherry picked from commit 6590dd0)
Kudo added a commit that referenced this pull request Dec 20, 2023
# Why

based on #25995 to integrate the new `deallocate()` in sqlite and fix
the NativeStatementBinding leakage

# How

integrate `deallocate()` from `SharedObject` and cleanup jni data

(cherry picked from commit 9d26a25)
onizam95 pushed a commit to onizam95/expo-av-drm that referenced this pull request Jan 15, 2024
# Why

notice the shared objects have never been deallocated

# How

- introduce the `JavaScriptWeakObject` that is similar to what we had on
ios and integrate to SharedObjectRegistry.
- add a new `deallocate` method for a derived shared object to be notified
when it is deallocated.

# Test Plan

test repro on https://github.com/ospfranco/expo-sqlite-benchmark
onizam95 pushed a commit to onizam95/expo-av-drm that referenced this pull request Jan 15, 2024
# Why

based on expo#25995 to integrate the new `deallocate()` in sqlite and fix
the NativeStatementBinding leakage

# How

integrate `deallocate()` from `SharedObject` and cleanup jni data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: fingerprint changed bot: passed checks ExpoBot has nothing to complain about
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants