I have a for loop to go trough all relationships for a single Core Data Object, and check if the relationship has a valid image:
let context = CDStack.persitentContainer.newBackgroundContext()
let counter = 0
let object = Object.find(by: UUID, in context)
context.perform {
for item in object.items {
guard let item = item as? ObjectItem else {
return
}
if let data = item.data {
if UIImage(data: data) != nil {
counter += 1
}
}
}
}
The issue is that the object has thousands of items and the memory is growing too quickly. Is there a way to remove the item from context memory once I have done the necessary check and incremented my counter?
Thank you.