简体   繁体   English

iPad中大量数据出现崩溃问题

[英]Crashing issue with large amount of data in iPad

I am working on the app in which large amount of data (eg 30K dictionary in array) is received through web service. 我正在研究其中通过Web服务接收大量数据(例如数组中的30K词典)的应用程序。 I am using JSON kit for parsing this large amount of data. 我正在使用JSON工具包来解析大量数据。 After getting response, i will store this data into plist file(because i want to run app in offline mode). 得到响应后,我会将这些数据存储到plist文件中(因为我想以离线模式运行应用程序)。

After that i am accessing this data using NSMutableArray(with 30K dictionary). 之后,我使用NSMutableArray(带有30K词典)访问此数据。 Now for further calculation i am using this array and use this loop 7- 8 times for calculation to draw the Graph. 现在,为了进行进一步的计算,我正在使用此数组,并使用此循环7至8次以进行计算以绘制图形。

//path = path from which i access the plist

NSMutableArray *array = [[NSMutableDictionary alloc] initWithContentsOfFile: path];

//where array contains about 30K dictionaries.

for(int i=0; i<[array count]; i++) {

    // some calculation formula
}

same loop is called 7-8 times after executing the above loop. 执行上述循环后,将调用同一循环7-8次。

My app is crashing after i read the data from plist due to memory issue. 由于内存问题,我从plist读取数据后,我的应用程序崩溃了。 Please help me to solve the problem. 请帮我解决问题。

As your issue is memory related you have to free the memory asap. 由于问题与内存有关,因此您必须尽快释放内存。 I assume that you are using ARC with iOS 6.0. 我假设您将ARC与iOS 6.0结合使用。 Try using the loop inside the @autoreleasepool and see if that makes any difference. 尝试使用@autoreleasepool内部的循环,看看是否有任何区别。 You can also use nested @autoreleasepool if you need. 如果需要,您还可以使用嵌套的@autoreleasepool。

for(int i=0; i<[array count]; i++) {
   @autoreleasepool {
       // calculation formula
    }
}

Old way; 旧方法;

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
for(int i=0; i<[array count]; i++) {
       // calculation formula
}
[pool drain];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM