我有一个类似于你@user2857148的问题。
我希望使用以下VC:
[self presentViewController:myViewController animated:YES completion:nil]
在
@implementation myViewController
中,我有以下代码:
- (void)viewDidLayoutSubviews
{
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
self.ballonMGScene = [[MBDBallonMiniGame alloc] initWithSize:skView.bounds.size andBallonImageNames:self.ballonObjectsArray];
self.ballonMGScene.parentVC = self;
self.ballonMGScene.scaleMode = SKSceneScaleModeAspectFill;
self.ballonMGScene.physicsWorld.gravity = CGVectorMake(0, 0);
[skView presentScene:self.ballonMGScene];
}
问题出在:
self.ballonMGScene.parentVC = self;
since in :
@interface MBDBallonMiniGame : SKScene <SKPhysicsContactDelegate>
parentVC被声明为strong:
@property (nonatomic,strong) WBMMiniGameVCTemplate *parentVC;
解答1:
解决方案1:
将其更改为:
@property (nonatomic,weak) WBMMiniGameVCTemplate *parentVC;
帮我解决了问题。
说明:
对于存储在某处的父级视图控制器(myViewController
),它是一个UIViewController
,已经被引用。由于这个VC对SKScene有强引用,所以它与之一起被存储。我甚至从这个SKScene中得到了控制台输出,就像它仍然活跃着一样。我猜测发生这种情况的原因是我有最多的强指针。
解决方案2:
在我的myViewController
下:
- (void)viewDidDisappear:(BOOL)animated
我打电话:
self.ballonMGScene.parentVC = nil;
当离开当前视图控制器(myViewController
)时,我将指针设置为nil,删除内存以及所有相关内容。
这两种解决方案对我有效。我使用调试器进行了测试,内存消耗正确地上升和下降。
希望这有助于理解问题和解决方案。