From 4601edf09e541372f2166c74de9478fbc3ad70b9 Mon Sep 17 00:00:00 2001 From: minggo Date: Fri, 6 Sep 2019 18:50:09 +0800 Subject: [PATCH] fix memory leak --- cocos/ui/UIVideoPlayer-ios.mm | 2 +- cocos/ui/UIWebViewImpl-ios.mm | 2 +- .../UIVideoPlayerTest/UIVideoPlayerTest.cpp | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cocos/ui/UIVideoPlayer-ios.mm b/cocos/ui/UIVideoPlayer-ios.mm index 1ef018e34dd8..248f6a285aac 100644 --- a/cocos/ui/UIVideoPlayer-ios.mm +++ b/cocos/ui/UIVideoPlayer-ios.mm @@ -87,7 +87,7 @@ @implementation UIVideoViewWrapperIos -(id)init:(void*)videoPlayer { if (self = [super init]) { - self.playerController = [AVPlayerViewController new]; + self.playerController = [[AVPlayerViewController new] autorelease]; [self setRepeatEnabled:FALSE]; [self showPlaybackControls:TRUE]; diff --git a/cocos/ui/UIWebViewImpl-ios.mm b/cocos/ui/UIWebViewImpl-ios.mm index f8245300f400..e7d353b7129f 100644 --- a/cocos/ui/UIWebViewImpl-ios.mm +++ b/cocos/ui/UIWebViewImpl-ios.mm @@ -124,7 +124,7 @@ - (void)dealloc { - (void)setupWebView { if (!self.wkWebView) { - self.wkWebView = [[WKWebView alloc] init]; + self.wkWebView = [[[WKWebView alloc] init] autorelease]; self.wkWebView.UIDelegate = self; self.wkWebView.navigationDelegate = self; } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp index 2e1ac03a6fca..d2d9f9d487b8 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp @@ -43,6 +43,10 @@ bool VideoPlayerTest::init() _visibleRect = Director::getInstance()->getOpenGLView()->getVisibleRect(); + // Should create video first to make sure video is destryed first. If not, then may crash. + // Because when destroying video, it will stop video which may trigger stopped event listener. + createVideo(); + MenuItemFont::setFontSize(16); auto fullSwitch = MenuItemFont::create("FullScreenSwitch", CC_CALLBACK_1(VideoPlayerTest::menuFullScreenCallback, this)); @@ -95,8 +99,6 @@ bool VideoPlayerTest::init() _loopStatusLabel->setAnchorPoint(Vec2::ANCHOR_MIDDLE_RIGHT); _loopStatusLabel->setPosition(Vec2(_visibleRect.origin.x + _visibleRect.size.width - 10,_visibleRect.origin.y + 185)); _uiLayer->addChild(_loopStatusLabel); - - createVideo(); return true; }