NSMutableDictionary removeAllObjects does not free up used memory!

I have a custom Objective-C ObjectCache class that utilized NSMutableDictionary to store named objects (specifically large NSImage objects).

The class has a maxItems property and clear method, which worked fine.

- (void)clear
{
    @synchronized(_cache)
    {
        [_cache removeAllObjects];
    }
}

But yesterday I received a customer feedback complaining one of my app consumes up to 24GB memory.

I verified that on my M1 Mac mini, and it's true. Even after calling clear method, memory usage shown in both Xcode debugger panel and Activity Monitor remains the same.

It did work before. Once I close a picture gallery window by calling clear method, memory usage dropped immediately as shown in Activity Monitor.

I suspect that this is a bug in ARM architecture. Does anyone else have same problem?

Accepted Reply

Maybe you need an autorelease pool.

  • Ah, yes. This is the second time I fell into the same pit. The last time was years ago... Just hate this design by Apple, why a tight loop cannot have ARC automatically?

Add a Comment

Replies

Maybe you need an autorelease pool.

  • Ah, yes. This is the second time I fell into the same pit. The last time was years ago... Just hate this design by Apple, why a tight loop cannot have ARC automatically?

Add a Comment