"Too many files open" problem used by FMDatabase / SQLite3

I use the FMDatabase wrapper for SQLite3 in my OSX application. I introduce a lot of database attachments:

FMResultSet *results;
results= [db executeQuery:@"select count(*) from `items` where key = ?",[keyPath lowercaseString],nil];

while([results next])
{
    if([results unsignedLongLongIntForColumnIndex:0]>0){
        updateOperation=TRUE;
    }
}
[results close];

if(updateOperation){

    [db executeUpdate:@"update `items` set OSXsize=?,OSXOsize=?, OSXDate=?, UUID=?,sourceFile=?,tombStone=0,SandBoxBookMark=?,songname=?,albumartist=? where key=?",
     size,originalSize, convertedDate,UUID,sourcePath,bookmark,fileName,albumArtist,[keyPath lowercaseString] , nil];
}
else
{
    [db executeUpdate:@"insert into `items`(key,filepath, OSXsize, OSXOsize, OSXdate,UUID,sourceFile,tombStone,SandBoxBookMark,songname,albumartist) values(?,?,?,?,?,?,?,0,?,?,?)",
     [keyPath lowercaseString], dapPath, size,originalSize, convertedDate,UUID,sourcePath,bookmark,fileName,albumArtist, nil];
}

I open the database once, however I see that 4725 + handlers are attached when the application is running in the activity monitor:

/Users/userA/Library/Containers/com.map-pin.Dapper/Data/Library/Application Support/com.map-pin.Dapper/dapperright.sqlite
15
16
...
4724
4725
+6
source share
2 answers

This is in a multi-threaded application and you create and open an instance dbevery time you update / insert a row? Do you have [db close];somewhere?

Have you tested FMDatabaseQueue ?

0
source

, , :

limit maxfiles 4096 16384 

. 16k .

OS X, OS X. ,

-1

Source: https://habr.com/ru/post/1017351/


All Articles