Solving memory leak in SearchKit CoreService

114 Views Asked by At

I have been working on a project using Apple's SearchKit. But I recently found a memory leak through instruments, which points to the SearchKit. Like the code below

guard
    let document = SKDocumentCreateWithURL(fileURL)?.takeRetainedValue()
else { return false }
defer { SKIndexFlush(indexFile) }
// Both SKIndexAddDocumentWithText and SKIndexAddDocument are builtin SearchKit
let addMethod: documentAddFunc = type == .nameOnly ? SKIndexAddDocumentWithText : SKIndexAddDocument
let textContent: CFString? = type == .nameOnly ? (fileName + " \(additionalNote)") as CFString : nil
return addMethod(indexFile, document, textContent, true)/* The line where instrument suggests the memory leak happened*/

Some explanations here: the two functions may be assigned to addMethod are both built in functions from SearchKit. indexFile is SKIndex type. document is created on the top of the picture, which should be correct.

So is this a bug on Apple's side or it's my problem to trigger this memory leak? Is there anything I can do to avoid or fix this?

Thank you very much!

0

There are 0 best solutions below