Reputation: 3028
I need to clean NSTextView indefinite amount of times. I do this with the following code:
@property IBOutlet NSTextView *textView;
```
[self.textView setString:@""];
but this code overflows memory if used unlimited amout of times. As a shortened example, this code:
loop:
[self.textView setString:@""];
goto loop;
overflows memory very quickly. How can I clean NSTextView unlimited number of times without overflowing the memory?
Upvotes: 0
Views: 125
Reputation: 385650
As you discovered, the following consumes memory without bound:
while (true) {
self.textView.string = @"";
}
However, this uses a fixed amount of memory:
while (true) {
@autoreleasepool {
self.textView.string = @"";
}
}
Upvotes: 1