相关疑难解决方法(0)

UIImageView.animationImages 后如何清除内存?

我创建了一个只有以下内容的新 Xcode 项目:

  • 从 png 拖入项目中创建 UIImages 数组的代码(我在将图像附加到数组时尝试了 UIImage(named:) 和 UIImage(contentsOfFile:))
  • 一个 UIImageView
  • 设置 imageView.animationImages = arrayOfImages 并调用 imageView.startAnimating() 的按钮

当按下按钮并播放动画时,内存使用量会增加 150-200MB,具体取决于图像数组中的图像数量。然后内存使用量保持在那个水平。

设置 imageView.animationImages = nil 不会清除内存。我怎么能去清除那个记忆?

任何的意见都将会有帮助。谢谢!

memory iphone animation ios swift

3
推荐指数
1
解决办法
1582
查看次数

为什么在 Swift 中每次调用 Decimal 类型的 formatted() 方法都会越来越慢?

我需要将整数分成 3 位数字,并研究formatted()该Decimal类型的方法。对随机整数每次
调用该formatted()类型的方法100,000 次会逐渐降低性能。 我想知道为什么会发生这种情况。Decimal

import Foundation

/// https://stackoverflow.com/a/56381954
func calculateTime(block : (() -> Void)) {
  let start = DispatchTime.now()
  block()
  let end = DispatchTime.now()
  let nanoTime = end.uptimeNanoseconds - start.uptimeNanoseconds
  let timeInterval = Double(nanoTime) / 1_000_000_000
  print("Time: \(timeInterval) seconds")
}

calculateTime { for _ in 0...100_000 { _ = Decimal(Int.random(in: 0...Int.max)).formatted() } }
calculateTime { for _ in 0...100_000 { _ = Decimal(Int.random(in: 0...Int.max)).formatted() } }
calculateTime { for _ in …
Run Code Online (Sandbox Code Playgroud)

swift

3
推荐指数
2
解决办法
140
查看次数

标签 统计

swift ×2

animation ×1

ios ×1

iphone ×1

memory ×1