diff --git a/react-native-pytorch-core/android/src/main/cpp/torchlive/media/audio/Audio.cpp b/react-native-pytorch-core/android/src/main/cpp/torchlive/media/audio/Audio.cpp index 255b6e4ce..9c8d95378 100644 --- a/react-native-pytorch-core/android/src/main/cpp/torchlive/media/audio/Audio.cpp +++ b/react-native-pytorch-core/android/src/main/cpp/torchlive/media/audio/Audio.cpp @@ -31,6 +31,13 @@ Audio::Audio(alias_ref audio) : audio_(make_global(audio)) { id_ = wrapObjectMethod(mediaUtilsClass, audio)->toStdString(); } +Audio::~Audio() { + ThreadScope::WithClassLoader([&]() { + Environment::ensureCurrentThreadIsAttached(); + this->audio_.release(); + }); +} + std::string Audio::getId() const { return id_; } diff --git a/react-native-pytorch-core/android/src/main/cpp/torchlive/media/audio/Audio.h b/react-native-pytorch-core/android/src/main/cpp/torchlive/media/audio/Audio.h index 20af56359..f853fbcf8 100644 --- a/react-native-pytorch-core/android/src/main/cpp/torchlive/media/audio/Audio.h +++ b/react-native-pytorch-core/android/src/main/cpp/torchlive/media/audio/Audio.h @@ -19,7 +19,7 @@ namespace media { class Audio : public IAudio { public: Audio(facebook::jni::alias_ref audio); - ~Audio() override = default; + ~Audio() override; std::string getId() const override;