fix memory leak

Signed-off-by: Ryan <fengxidadi@163.com>
This commit is contained in:
Ryan 2024-02-28 11:11:17 +08:00
parent da475da9cc
commit 325bd5bc6e
3 changed files with 10 additions and 6 deletions

View File

@ -30,16 +30,17 @@ export struct NoPhotoComponent {
@StorageLink('leftBlank') leftBlank: number[]
= [0, ScreenManager.getInstance().getStatusBarHeight(), 0, ScreenManager.getInstance().getNaviBarHeight()];
@State bigScreen: boolean = false;
private updateImageLayoutFunc: Function = (): void => this.updateImageLayout();
aboutToAppear(): void {
Log.info(TAG, `aboutToAppear`);
ScreenManager.getInstance().on(ScreenManager.ON_WIN_SIZE_CHANGED, (): void => this.updateImageLayout());
ScreenManager.getInstance().on(ScreenManager.ON_WIN_SIZE_CHANGED, this.updateImageLayoutFunc);
this.updateImageLayout();
}
aboutToDisappear(): void {
Log.info(TAG, 'aboutToDisappear');
ScreenManager.getInstance().off(ScreenManager.ON_WIN_SIZE_CHANGED, (): void => this.updateImageLayout());
ScreenManager.getInstance().off(ScreenManager.ON_WIN_SIZE_CHANGED, this.updateImageLayoutFunc);
}
build() {

View File

@ -75,7 +75,7 @@ export struct ThirdSelectPhotoBrowserBase {
bundleName: string = '';
isMultiPick = true;
mTransition: string = '';
controller: SwiperController = new SwiperController();
controller?: SwiperController = new SwiperController();
@Provide('transitionIndex') currentIndex: number = 0;
@State currentUri: string = '';
isFromFa: boolean = false;
@ -177,6 +177,7 @@ export struct ThirdSelectPhotoBrowserBase {
}
this.dataSource.release();
mMultimodalInputManager.unregisterListener();
this.controller = undefined;
}
onDataSizeChanged(size: number): void {
@ -287,7 +288,7 @@ export struct ThirdSelectPhotoBrowserBase {
onBackPress() {
if (this.geometryTransitionEnable) {
this.controller.finishAnimation((): void => this.onBackPressInner());
this.controller?.finishAnimation((): void => this.onBackPressInner());
} else {
router.back({
url: '',

View File

@ -132,7 +132,7 @@ export struct PhotoBrowserComponent {
albumUri = '';
// swiper currentIndex, there may not be onChanged callback during data refresh, so mediaItem cannot be saved
@Provide('transitionIndex') currentIndex: number = Constants.NUMBER_0;
controller: SwiperController = new SwiperController();
controller?: SwiperController = new SwiperController();
@Prop @Watch('onPageChanged') pageStatus: boolean = false;
@StorageLink('geometryOpacity') geometryOpacity: number = 1;
@State geometryTransitionId: string = '';
@ -596,7 +596,7 @@ export struct PhotoBrowserComponent {
onBackPress(): boolean {
Log.info(TAG, 'onBackPress');
this.appBroadCast.emit('hideBar', []);
this.controller.finishAnimation((): void => this.onBackPressInner());
this.controller?.finishAnimation((): void => this.onBackPressInner());
return true;
}
@ -713,6 +713,8 @@ export struct PhotoBrowserComponent {
this.broadCast.off(PhotoConstants.SET_DISABLE_SWIPE, this.setSwiperDisableFunc);
this.broadCast.off(BroadCastConstants.ON_DATA_RELOADED_WITH_EDIT, this.onDataReloadWithEditFunc);
this.appBroadCast.off(BroadCastConstants.PHOTO_BROWSER_BACK_PRESS_EVENT, this.photoBrowserBackFunc);
this.controller = undefined;
}
getAlbumUriByUri(albumUri: string) {