如何解决SpriteKit 与 SwiftUI 内存泄漏?
我需要帮助。我有一个 SpriteKit 场景并使用更新功能来更改场景的属性。此属性用于 ZStack 中的圆形视图。当我点击按钮时,Xcode 的泄漏工具中检测到内存泄漏。这是一个错误还是为什么会发生这种情况?按钮只是在控制台上打印一些东西。
import SwiftUI
import SpriteKit
class Game: SKScene,ObservableObject{
@Published var lenght: CGFloat = 1
var up: Bool = false
func change(){
if self.lenght > 200 {
up = false
}else if (self.lenght < 5){
up = true
}
up ? (self.lenght += 1) : (self.lenght -= 1)
}
override func update(_ currentTime: TimeInterval) {
self.change()
}
}
struct ContentView: View {
@Observedobject var game = Game()
var body: some View {
ZStack{
SpriteView(scene: game)
Circle().frame(width: game.lenght,height: game.lenght)
.foregroundColor(.white)
Button("hello"){
print("hello")
}
.frame(width: 50,height: 20)
.foregroundColor(.black)
.background(Color.blue)
}
}
}
泄漏是:nsxpcconnection remoteObjectProxyWithErrorHandler
如果我将按钮更改为:
Button("hello"){
print("hello")
game.lenght = 30
}
然后在Malloc 64 Byte条目中QuartzCore之间出现了这个库:
“AxcoreUtilities”
我真的希望有人知道这里发生了什么。感谢您的回答。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。