Reduce Peak Memory Usage With @autoreleasepool

后端 未结 2 1080
挽巷
挽巷 2020-12-28 23:23

I work on an iPad application that has a sync process that uses web services and Core Data in a tight loop. To reduce the memory footprint according to Apple\'s Recomendatio

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-29 00:13

    The following should achieve the same thing as the goto answer without the goto:

    for (NSUInteger count = 0; count < MAX_ALLOCATIONS;)
    {
        @autoreleasepool
        {
            for (NSUInteger j = 0; j < BATCH_SIZE && count < MAX_ALLOCATIONS; j++, count++)
            {
                NSString *text = [NSString stringWithFormat:@"%u", count + 1U];
                [text class];
            }
        }
    }
    

提交回复
热议问题