Kibernetik
Kibernetik

Reputation: 3028

How to clean NSTextView?

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

Answers (1)

rob mayoff
rob mayoff

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

Related Questions