Javascript 反应本机动画/重新激活的内存泄漏
关于典型信息的一个问题 警告:无法对已卸载的组件执行React状态更新。这是一个no-op,但它表示应用程序中存在内存泄漏。要修复此问题,请取消useEffect清理函数中的所有订阅和异步任务 我正在分析我的应用程序的性能,我注意到在解决了我的组件中的一些内存泄漏后,我的应用程序的性能显著提高 我面临着一个内存泄漏,我已经实现了一个缓存的渐进式图像组件,它使用Animated.timing()来更新我的动画状态值 这样做:Javascript 反应本机动画/重新激活的内存泄漏,javascript,reactjs,react-native,memory-leaks,expo,Javascript,Reactjs,React Native,Memory Leaks,Expo,关于典型信息的一个问题 警告:无法对已卸载的组件执行React状态更新。这是一个no-op,但它表示应用程序中存在内存泄漏。要修复此问题,请取消useEffect清理函数中的所有订阅和异步任务 我正在分析我的应用程序的性能,我注意到在解决了我的组件中的一些内存泄漏后,我的应用程序的性能显著提高 我面临着一个内存泄漏,我已经实现了一个缓存的渐进式图像组件,它使用Animated.timing()来更新我的动画状态值 这样做: _isMounted = false; // Track the
_isMounted = false; // Track the component mounted status
state = {
isLoading: this.props.withLoading,
imageOpacity: new Animated.Value(0),
thumbnailOpacity: new Animated.Value(0),
};
onLoadImage = () => {
// Only update the state if the component is mounted
if (!this._isMounted) return; // <------------------------ SOLVE THE MEMORY LEAK FOR isLoading update
this.setState({ isLoading: false }, this.startLoadImageAnimation);
};
startLoadImageAnimation = () => {
// Only update the state if the component is mounted
if (!this._isMounted) return; // <----------- Seems to not being solving the possible memory leak with the animated stateful value updates
const { withFade, onLoadImage } = this.props;
const { imageOpacity } = this.state;
if (withFade) {
const { imageFadeDuration } = this.props;
Animated.timing(imageOpacity, {
toValue: 1,
easing: Easing.linear,
duration: imageFadeDuration,
useNativeDriver: true,
}).start();
}
onLoadImage();
};
componentDidMount() {
this._isMounted = true;
}
componentWillUnmount() {
this._isMounted = false;
}
\u isMounted=false;//跟踪组件安装状态
状态={
isLoading:this.props.withLoading,
imageOpacity:新的动画值(0),
thumbnailOpacity:新的动画值(0),
};
onLoadImage=()=>{
//仅在安装组件时更新状态
如果(!this._isMounted)返回;//{
//仅在安装组件时更新状态
如果(!this._isMounted)返回//