SQLite Persistence类的ARC内存问题

时间:2013-01-31 15:16:13

标签: iphone objective-c memory-leaks automatic-ref-counting

使用SQLitePersistence类将数据插入数据库时​​,我无法弄清楚应用崩溃的原因。

从webservice下载产品xml数据后,我试图将所有产品详细信息插入各种表中,如

Product 
Product_image
Product_option
Product_categories
Product_custom_option

就目前而言,我们在网络服务上提供了800种产品,未来可能会增加约2000种产品。

我的问题:在插入400到450个产品后,应用会定期崩溃。然后我将@autorelesepool用于将数据插入数据库的每个循环。它会增加500到550个产品然后应用程序崩溃,我可以做些什么来避免应用程序崩溃?

我的产品表SQLitePersistence文件的.h数据库类:

#import <Foundation/Foundation.h>
#import "SQLitePersistentObject.h"

@interface iMobDB : SQLitePersistentObject
{
    NSString *sku;
    NSString *name;
    .....
    .....
}
@property(nonatomic,retain) NSString *sku;
@property(nonatomic,retain) NSString *name;
.....
.....
@end

.m档案

@implementation iMobDB

@synthesize sku;
@synthesize name;
    .....
    .....

-(void) dealloc
{
    for (NSString *one in [[self class] propertiesWithEncodedTypes])
    {
        [self removeObserver:self forKeyPath:one];
    }
    iMobReleaseNil(sku);
    iMobReleaseNil(name);
    .....
    .....
}

我在Appdelegate

中插入数据
 /*===================================== Save Product Information ===============================================*/

        iMobDB *imobdb = [[iMobDB alloc]init];
        imobdb.productId = [productid intValue];
        imobdb.sku = skukey;
        imobdb.name = namekey;
        imobdb.optionalOption = [NSString stringWithFormat:@"%d",options];
        imobdb.requriedOption = [NSString stringWithFormat:@"%d",requried];
        imobdb.productType = producttypekey;
        imobdb.price = pricekey;
        imobdb.specialprice = specialpricekey;
        imobdb.stock = [stock intValue];
        imobdb.manufacture = manukey;
        [imobdb save];
        imobdb=nil;

        /*==============================================================================================================*/

        /*==================================== Save Product Images =====================================================*/
       __unsafe_unretained NSDictionary  *imagearray=[[dict objectForKey:@"images"] objectForKey:@"url"];

        @autoreleasepool 
        {

        for (NSDictionary *dict in imagearray)
        {
            if ([dict  isKindOfClass:[NSArray class]])
            {
                NSString *imageurl=[dict objectForKey:@"text"];                
                ImageDB *imagedb = [[ImageDB alloc] init];
                imagedb.productId = [productid intValue];
                imagedb.imageurl = imageurl;
                [imagedb save];
                imagedb=nil;
            }
            else if([dict  isKindOfClass:[NSDictionary class]])
            {
                NSString *imageurl=[dict objectForKey:@"text"];              
                ImageDB *imagedb = [[ImageDB alloc] init];
                imagedb.productId = [productid intValue];
                imagedb.imageurl = imageurl;
                [imagedb save];
                imagedb=nil;
            }
        }

        }
        /*===============================================================================================================*/

        /*==================================== Save Category ============================================================*/
        @autoreleasepool 
        {

      __unsafe_unretained  NSDictionary *categorydict = [dict objectForKey:@"categories"];

                for (NSDictionary *dictt in catedict)
                {
                 __unsafe_unretained   NSString *categoryid=[[dictt objectForKey:@"categoryId"]objectForKey:@"text"];
                __unsafe_unretained    NSString *categoryname=[[dictt objectForKey:@"categoryName"]objectForKey:@"text"];                    
                    Categories *catdb  = [[Categories alloc] init];
                    catdb.categoryId = [categoryid intValue];
                    catdb.categoryname = categoryname;
                    catdb.productId = [productid intValue];
                    [catdb save];
                    catdb=nil;
                }
            }

请注意:我已在以下课程中禁用ARC

enter image description here

错误日志屏幕截图

enter image description here

错误日志

  

Feb 1 11:53:59 Innoppl-iPod backboardd [52]:iMob [2811]有   超出允许时间的主动断言:{(          identifier:挂起进程:iMob [2811] allowedBackgroundDuration:10.000000 reason:suspend   所有者pid:52 preventSuspend preventThrottleDownCPU   preventThrottleDownUI)} 2月1日11:53:59 Innoppl-iPod backboardd [52]   :强制iMob崩溃报告[2811] ... 2月1日11:53:59   Innoppl-iPod backboardd [52]:完成崩溃报告。二月   1 11:53:59 Innoppl-iPod ReportCrash [2819]:libMobileGestalt   copySystemVersionDictionaryValue:无法从中查找ReleaseType   系统版字典2月1日11:53:59 Innoppl-iPod   com.apple.launchd 1   (UIKitApplication:com.innoppl.Saletab [0xe1bf] [2811]):   (UIKitApplication:com.innoppl.Saletab [0xe1bf])已退出:已杀:2月9日   1 11:53:59 Innoppl-iPod backboardd [52]:应用程序   'UIKitApplication:com.innoppl.Saletab [0xe1bf]'异常退出   信号9:被杀:9月1日11:53:59 Innoppl-iPod ReportCrash [2819]   :保存的crashreport到   /var/mobile/Library/Logs/CrashReporter/iMob_2013-02-01-115359_Innoppl-iPod.plist   使用uid:0 gid:0,synthetic_euid:501 egid:0

0 个答案:

没有答案