Thursday, 19 September 2013

Objective-c iPhone : Region allocation error NSString memory limit?

Objective-c iPhone : Region allocation error NSString memory limit?

When using this code in xcode for iphone I get an allocation
region error. (Using simulater)
NSString* str =@"Sommetext";
for (int i =1; i < 50 ; i++) {
str = [[[str stringByAppendingString:@"\n"]
stringByAppendingString:str] stringByAppendingString:@""];
NSLog([NSString stringWithFormat:@"%d",i]);
}
Monitoring the log shows an increase from 1 till 26 and then
crashes with the following error.
Appname(239,0xac5c9a28) malloc: * mmap(size=805306368) failed (error
code=12) * error: can't allocate region
However running the same code (in java) on my android (Samsung
Galaxy S2) has no problems even when I loop it 1000 times.

No comments:

Post a Comment