Iphone SQLitePersistence类的ARC内存问题
使用Iphone SQLitePersistence类的ARC内存问题,iphone,objective-c,memory-leaks,automatic-ref-counting,Iphone,Objective C,Memory Leaks,Automatic Ref Counting,使用SQLitePersistenceclass将数据插入数据库时,我无法找出应用程序崩溃的原因 从webservice下载产品xml数据后,我尝试将所有产品详细信息插入到各个表中,如 Product Product_image Product_option Product_categories Product_custom_option 目前,我们在Web服务上有800种产品,未来可能会增加约2000种产品 我的问题是:在插入400到450个产品后,应用程序经常崩溃。然后我使用@autor
SQLitePersistence
class将数据插入数据库时,我无法找出应用程序崩溃的原因
从webservice下载产品xml数据后,我尝试将所有产品详细信息插入到各个表中,如
Product
Product_image
Product_option
Product_categories
Product_custom_option
目前,我们在Web服务上有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
我正在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
错误日志屏幕截图
错误日志
2月1日11:53:59 Innoppl iPod BackboardDD[52]:iMob[2811]已经
超出允许时间的主动断言:{(
标识符:挂起进程:iMob[2811]permittedBackgroundDuration:10.000000原因:挂起
所有者pid:52 PreventSuspendPreventThrottleDownCPU
已防节流(Wnui)}2月1日11:53:59 Innoppl iPod BackboardDD[52]
:iMob的强制碰撞报告[2811]。。。二月一日11:53:59
Innoppl iPod backboardd[52]:已完成碰撞报告。二月
1 11:53:59 Innoppl iPod ReportCrash[2819]:LibMobileGetStalt
copySystemVersionDictionaryValue:无法从中查找ReleaseType
系统版本字典2月1日11:53:59 Innoppl iPod
com.apple.launchd
(UIKitApplication:com.innoppl.Saletab[0xe1bf][2811]):
(UIKitApplication:com.innoppl.Saletab[0xe1bf])退出:终止:2月9日
1 11:53:59 Innoppl iPod BackboardDD[52]:应用程序
“UIKitApplication:com.innoppl.Saletab[0xe1bf]”已异常退出,原因是
信号9:死机:2月9日11:53:59 Innoppl iPod报告崩溃[2819]
:已将crashreport保存到
/var/mobile/Library/Logs/CrashReporter/iMob_2013-02-01-115359_Innoppl-iPod.plist
正在使用uid:0 gid:0、synthetic\u euid:501 egid:0
所有这些都存储在内存中还是文件中?请发布崩溃的堆栈跟踪。@Resh32所有数据都使用SQLitePersistence类存储在SQLite数据库中。@trojanfoe上面我附上了错误日志报告的屏幕截图OK,这不是堆栈跟踪,但这是因为应用程序是用
SIGKILL
终止的,这意味着我认为你找不到任何线索。是时候通过工具运行你的应用程序了
leak
工具。。。
/*===================================== 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;
}
}