Reputation: 461
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
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