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?

Answered by galad87 in 782344022

Maybe you need an autorelease pool.

Accepted Answer

Maybe you need an autorelease pool.

NSMutableDictionary removeAllObjects does not free up used memory!
 
 
Q