My test is on Mac OS X, and I think you're talking about the iPhone platform.
The fact is, I donβt see how returning an error from the appendString method will help, because the platform is at this point in such a state that it cannot satisfy the malloc requests for your process.
To get around this problem, you can probably malloc your own address space and use this managed process memory as storage for your lines. I think Carbon CFString (free paid up to NSString) allows you to use your own memory allocator.
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [NSAutoreleasePool new];
NSMutableString * m = [NSMutableString stringWithCapacity:100000];
int i;
for(i=0;i<1000000;i++)
[m appendString:@"ABCDE..."]; //1400 characters long
[pool release];
}
cd:tmp diciu$ ./a.out
a.out(2216) malloc: *** mmap(size=1220067328) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
[..]
2009-08-13 16:45:44.163 a.out[2216:10b] *** Terminating app due to uncaught exception 'NSMallocException', reason: 'Out of memory. We suggest restarting the application. If you have an unsaved document, create a backup copy in Finder, then try to save.'
2009-08-13 16:45:44.165 a.out[2216:10b] Stack: (
2494541803,
2485014075,
2435399864,
2494157025,
2494172776,
2434276628
)
Trace/BPT trap
diciu source
share