我使用的是ARKit。我需要将相机中的视图保存到相册中。因此,我在故事板中添加了一个按钮,以及如下所示的函数:
@IBAction func saveScreenshot() {
let snapShot = self.sceneView.snapshot()
UIImageWriteToSavedPhotosAlbum(snapShot, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)
}
@objc func image(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) {
// ...
}但当我多次点击按钮时,我的应用程序就会崩溃。因此,我转到“调试导航器”,并看到内存上升约30M,一旦我点击按钮(如200M - 235M - 260M 500M+)。
发生了什么?那我该怎么办呢?
发布于 2018-11-05 18:59:06
我在Scenekit中遇到了同样的问题(仅在iOS12上;相同的构建在iOS11上运行良好)。现在,我找到了一个解决办法:我使用SCNRenderer的snapshot(atTime:with:antialiasingMode:)方法,而不是使用SCNView的snapshot()方法。这需要做一些额外的工作:
我已经更换了我的let snapShot = scenView.snapShot
下面4行(注意:我没有动画,所以TimeInterval(0)对我来说是可以的):
let renderer = SCNRenderer(device: MTLCreateSystemDefaultDevice(), options: [:]) renderer.scene = scene renderer.pointOfView = sceneView.pointOfView let snapShot = renderer.snapshot(atTime: TimeInterval(0), with: size, antialiasingMode: .none)
发布于 2020-07-16 22:35:25
我遇到了这个问题,但我发现在主线程上调用快照方法可以解决内存泄漏问题。
https://stackoverflow.com/questions/51397382
复制相似问题