I'm interested in learning more about how best to handle memory management under tight loops with ARC. In particular, I've got an app I'm writing which has a `while` loop which rus for a really long time, and I've noticed that despite having implemented (what I believe to be) the best practices in ARC, the heap keeps growing boundlessly.

To illustrate the problem I'm having, I first set up the following test to fail on purpose:

```
while (true) {         
    NSMutableArray *array = [NSMutableArray arrayWithObject:@"Foo"];
    [array addObject:@"bar"]; // do something with it to prevent compiler optimisations from skipping over it entirely
}

```

Running this code and profiling with the Allocations tool shows that the memory usage just endlessly increases. However, wrapping this in an `@autoreleasepool` as follows, immediately resolves the issue and keeps the memory usage nice and low:

```
while (true) {
    @autoreleasepool {         
        NSMutableArray *array = [NSMutableArray arrayWithObject:@"Foo"];
        [array addObject:@"bar"];
    }
}

```

Perfect! This all seems to work fine -- and it even works fine (as would be expected) for non-autoreleased instances created using `[[... alloc] init]`. Everything works fine until I start involving any `UIKit` classes.

For example, let's create a `UIButton` and see what happens:

```
while (true) {
    @autoreleasepool {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        button.frame = CGRectZero;
    }
}

```

Now, the memory usage increases ad infinitum -- effectively, it appears that the `@autoreleasepool` is having no effect.

So the question is **why does `@autoreleasepool` work fine for the `NSMutableArray` and keep the memory in-check, but when applied to a `UIButton` the heap continues to grow?**

Most importantly, how can I keep the heap from expanding endlessly when using `UIKit` classes in an endless loop like this, and what does this tell us about the best practices for ARC in `while(true)` or `while(keepRunningForALongTime)` style loops?

My gut feeling on this is (and I could be totally wrong) is that it's perhaps something about how the `while (true)` keeps the runloop from cycling, which is keeping the `UIKit` instances in memory rather than releasing them... But clearly I'm missing something in my understanding of ARC!

(And to eliminate an obvious cause, `NSZombiedEnabled` is not enabled.)