Error: "cannot open database file" and "Too many open files"

I checked a lot of SO questions like this and those related to these errors, but let me tell you my script.

I load images into the view and after clicking on the objects in the collection view 18 times, my code returns this error. I am not doing anything complicated. I just add the same asset that was clicked on the view above this asset.

Information: I create assets and save them in the document catalog and receive them only from there.

Below is my code where the error occurs:

let data = try Data(contentsOf: URL(fileURLWithPath: (contentsOfFile: (userInfo[kPath] as! String))), options: .uncached)

I try to get imageData and then put it as an image in an image, but after a few clicks, the Try statement returns the following errors.

"Too many open files"

I also tried another way of loading the image ie

UIImage(contentsOfFile: imageFilePath)!

but the result will be the same.

Can someone help me by guiding how to solve this error?

+4
source share
1 answer

The code that you shared with us is unlikely to be the source of the “too many files” problem, but rather is a symptom of another problem. Your other mistake, “unable to open the database file”, suggests a more likely culprit, for example. you can open databases, but not close them properly, ending up with too many files.

, , . , API sqlite3, , . , , , "" "".

Swift, if guard, "close" defer .


contentsOfFile /. :

let data = try Data(contentsOf: URL(fileURLWithPath: userInfo[kPath] as! String), options: .uncached)
+3

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


All Articles