Skip to content

Commit 827e771

Browse files
minggoMike Chen
authored and
Mike Chen
committed
fix memory leak (cocos2d#20110)
1 parent 85ec4f6 commit 827e771

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

cocos/ui/UIVideoPlayer-ios.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ @implementation UIVideoViewWrapperIos
8787
-(id)init:(void*)videoPlayer
8888
{
8989
if (self = [super init]) {
90-
self.playerController = [AVPlayerViewController new];
90+
self.playerController = [[AVPlayerViewController new] autorelease];
9191

9292
[self setRepeatEnabled:FALSE];
9393
[self showPlaybackControls:TRUE];

cocos/ui/UIWebViewImpl-ios.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ - (void)dealloc {
124124

125125
- (void)setupWebView {
126126
if (!self.wkWebView) {
127-
self.wkWebView = [[WKWebView alloc] init];
127+
self.wkWebView = [[[WKWebView alloc] init] autorelease];
128128
self.wkWebView.UIDelegate = self;
129129
self.wkWebView.navigationDelegate = self;
130130
}

tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ bool VideoPlayerTest::init()
4343

4444
_visibleRect = Director::getInstance()->getOpenGLView()->getVisibleRect();
4545

46+
// Should create video first to make sure video is destryed first. If not, then may crash.
47+
// Because when destroying video, it will stop video which may trigger stopped event listener.
48+
createVideo();
49+
4650
MenuItemFont::setFontSize(16);
4751

4852
auto fullSwitch = MenuItemFont::create("FullScreenSwitch", CC_CALLBACK_1(VideoPlayerTest::menuFullScreenCallback, this));
@@ -95,8 +99,6 @@ bool VideoPlayerTest::init()
9599
_loopStatusLabel->setAnchorPoint(Vec2::ANCHOR_MIDDLE_RIGHT);
96100
_loopStatusLabel->setPosition(Vec2(_visibleRect.origin.x + _visibleRect.size.width - 10,_visibleRect.origin.y + 185));
97101
_uiLayer->addChild(_loopStatusLabel);
98-
99-
createVideo();
100102

101103
return true;
102104
}

0 commit comments

Comments
 (0)