Josh Sklar
Josh Sklar

Reputation: 461

iOS: Check if system has enough memory

In C, you can check if the system has enough free memory by checking the return value of a call to malloc(). How do you check if the system has enough free memory in Objective-C? Does alloc throw an exception if there is not enough memory?

I have created a class that derives from NSObject for an in-memory photo cache. I need to check before saving something into the cache if there is enough memory, and can't quite figure out the proper way to do so.

Thanks

Upvotes: 0

Views: 258

Answers (1)

user1118321
user1118321

Reputation: 26375

-alloc will return nil if it is unable to allocate the memory requested. Just check that the return value is non-nil.

Upvotes: 1

Related Questions