gpt4 book ai didi

Swift:内存压力事件 2 vm 0

转载 作者:行者123 更新时间:2023-12-03 09:23:17 25 4
gpt4 key购买 nike

我在 Xcode 控制台中看到一条消息 Received memory pressure event 1 vm pressure 0 .我不确定是什么原因造成的,为什么但我知道当我在相机 View Controller 中时会打印。我猜这没什么可担心的(还),但它是否指向我应该尽快修复的问题?

FirstViewController: UIViewController {

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
let image = info[UIImagePickerController.InfoKey.editedImage] as! UIImage
let croppedImage = cropToBounds(image: image, width: 10, height: 10)
self.productImage.image = croppedImage
print("size: \(croppedImage.size)")
print("original size: \(image.size)")
self.dismiss(animated: true, completion: nil)
}

func setupCameraPicker() {
if UIImagePickerController.isSourceTypeAvailable(.camera) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .camera;
imagePicker.allowsEditing = true
self.present(imagePicker, animated: true, completion: nil)
}
}
}

最佳答案

autoreleasepool

autoreleasepool { 
let image = info[UIImagePickerController.InfoKey.editedImage] as! UIImage
let croppedImage = cropToBounds(image: image, width: 10, height: 10)
self.productImage.image = croppedImage
print("size: \(croppedImage.size)")
print("original size: \(image.size)")
self.dismiss(animated: true, completion: nil)
}
尝试将您的代码放入 autoreleasepool
Foundation 的 NSAutoreleasePool 类型,后来抽象为 @autoreleasepool 块,在 iOS 开发中是一个非常古老的概念。在 iOS 的 Obj-C 时代,这种类型的使用对于防止您的应用程序的内存在特定情况下爆炸很重要。随着 ARC 和 Swift 的出现和发展,很少有人仍然需要手动玩弄内存,这使得看到它变得罕见。

关于Swift:内存压力事件 2 vm 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56239425/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com