0
我有一个非常简单的Swift类,它只有一个静态方法,此方法分配3个字符串数组,并通过追加这些数组中的元素来创建一个随机字符串。内存泄漏[String]常量
下面的代码:
public static func generateText() -> String {
let phraseComponent1 = [
"Line 1,",
"Line2,",
"Line3,",
"Line4,",
"Line5,",
"Line6,"]
let phraseComponent2 = [
"Line 1,",
"Line2,",
"Line3,",
"Line4,",
"Line5,",
"Line6,"]
let phraseComponent3 = [
"Line 1,",
"Line2,",
"Line3,",
"Line4,",
"Line5,",
"Line6,"]
let componentIndex1 = Int(arc4random_uniform(UInt32(phraseComponent1.count)))
let componentIndex2 = Int(arc4random_uniform(UInt32(phraseComponent2.count)))
let componentIndex3 = Int(arc4random_uniform(UInt32(phraseComponent3.count)))
let phrase1 = phraseComponent1[componentIndex1]
let phrase2 = phraseComponent2[componentIndex2]
let phrase3 = phraseComponent3[componentIndex3]
return "\(phrase1) \(phrase2) \(phrase3)"
}
有人能告诉我一个理由它?以及如何解决这个问题
如果你用这个方法数十亿次抛弃返回值并且耗尽自动释放池,你会看到堆增长吗?如果没有,这是一个误导性的诊断输出,你不应该担心它。 – werediver