开发者

fmdb iphone 3g large array

开发者 https://www.devze.com 2023-03-12 22:55 出处:网络
I am having some trouble over fmdb with iphone 3g with firmware:4.2.1 (8C148). I have a large NSMutableArray that contains sql commands (downloaded from a database). I populate the NSMutableArray via

I am having some trouble over fmdb with iphone 3g with firmware:4.2.1 (8C148). I have a large NSMutableArray that contains sql commands (downloaded from a database). I populate the NSMutableArray via NSAutoreleasePool (part of releasing some memory for iphone 3g), and I get a 40+ mb array.

Then, I use the following commands:

 [db beginTransaction];
 for (NSString* sql in updateSQL)
 {
  if (sql!开发者_高级运维=@"") {
   BOOL fmtest = [db executeUpdate:sql];
   if (!fmtest) {
    NSLog(@"Sql FAIL: %@",sql);
   }
   if ([db hadError]) {
    NSLog(@"Err %d: %@", [db lastErrorCode], [db lastErrorMessage]);
   }
 }
 // fetches--; // Counter of total updates;
}
[db commit];

During the update process, I get a 40/50 Mb memory allocation. Iphone 3g can't handle that and it fails miserably with level 1 warnings and finally exiting.

I tried it on iphone 3GS and it works fine.

Does anyone have any idea on how to skip that? I can't use core data (even though it's a great solution) because I have already a large database premade bundled with the app.


Close the DB between calls using

[db close];

To make sure free the memory no longer in use.

Most developers try to keep the DB connection open as long as possible. However on the iPhone - with memory the tightest constrain and IO fast - repeatedly opening/closing the DB for each call is faster most of the time.

0

精彩评论

暂无评论...
验证码 换一张
取 消