我需要无限期地清理NSTextView。我用下面的代码来做这件事:
@property IBOutlet NSTextView *textView;self.textView设置字符串:@“”;
but this code overflows memory if used unlimited amout of times. As a shortened example, this code:
```javascript循环:
self.textView设置字符串:@“”;
转到循环;
内存溢出速度非常快。如何在不溢出内存的情况下无限次清理NSTextView?
发布于 2019-05-25 14:57:12
正如您所发现的,以下内容会无限制地消耗内存:
while (true) {
self.textView.string = @"";
}但是,这使用了固定数量的内存:
while (true) {
@autoreleasepool {
self.textView.string = @"";
}
}https://stackoverflow.com/questions/56301769
复制相似问题