Re: Allocating too much memory kills my App rather than returning NULL
Re: Allocating too much memory kills my App rather than returning NULL
- Subject: Re: Allocating too much memory kills my App rather than returning NULL
- From: James Montgomerie <email@hidden>
- Date: Wed, 09 Nov 2011 10:59:52 +0000
On 9 Nov 2011, at 08:08, Don Quixote de la Mancha wrote:
> That would be great if I actually received any memory warnings. I don't.
...
> However, I did set a breakpoint at both methods. That breakpoint was never hit.
I dont want to wade in to the religious war here (although I'm on the side of pragmatism, as you might be able to tell soon anyway...), so just on a practical level:
Reading between the lines (and with apologies if I've inferred incorrectly), I think the reason you're not getting these warnings is because you are allocating your memory in a loop on the main thread. The main thread must be free to run the application runloop to deliver these warnings - that's how they work, they're not delivered asynchronously in the background. If you want to listen for them while your allocation loop is going on, you'll need to run it on a background thread or queue or (or otherwise free up the runloop to run by e.g. batching allocation calls). To be honest though, I would be very skeptical that you could respond to the warnings in a reliable or timely enough manner to satisfy the OS in all cases, so although you might want to try this out to see how the system works first-hand, I don't think it's a plausible strategy to use in shipping software.
Also, again on a practical level, you might not /like/ the fact that there's no way to know if an allocation call will succeed, how much physical memory is available to you, or that, even if you could know that, the value would vary over time, but that's how iOS works. Your program will need to cope with that.
Jamie.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden