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.
UPDATE 1:
Running the code in the background using GCD returns the same error so it isn't a main thread overload problem.
UPDATE 2:
Android java code that works fine
String MsgText = "Some text";
for(i = 0 ; i < amount; i++)
{
////Works on amount < 10000
//Tested on Galaxy S2 **1GB Ram**
MsgText = MsgText + MsgText;
}