Running out of VM
Running out of VM
- Subject: Running out of VM
- From: Phill Kelley <email@hidden>
- Date: Thu, 22 Dec 2005 22:08:47 +1100
Hi List!
I have written a small test app that keeps creating objects until it runs
out of virtual memory. When VM is exhausted, I get the message:
vm_allocate(size=xxxx) failed (error code = 3)
error: can't allocate region
set a breakpoint in szone_error to debug
For some reason, I have always assumed that sending an alloc message to a
class when there was insufficient VM would return nil, that sending an init
message to a nil object was safe, and that this code would always work:
MyClass *mine = [[MyClass alloc] init];
if (!mine)
NSLog(@"out of virtual memory");
Now that I have come to read the documentation for NSObject +alloc, there
is no suggestion that this is meant to be the case.
However, the documentation for NSData (which is what I am actually
creating) and in particular the +dataWithBytes:length: message (which is
what I am using) explicitly states that nil will be returned if the object
can't be created.
My questions:
1. Why are NSData allocations (typically on the order of 2K bytes)
crashing instead of returning nil?
2. Is there anything I should be doing to cause NSData to return nil
when the app runs out of VM?
3. Is a crash the expected behavior in this situation for all kinds
of objects, or do other people on this list also think that alloc
will return nil instead of crashing?
I have tested NSData, NSString and a nonsense object of my own and they all
exhibit the same behavior.
And, yes, I really do appreciate that 4GB of VM ought to be enough for
anyone. I am simply trying to make my code bullet-proof.
Cheers, PK
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden