mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-11 20:00:30 +01:00
Memory leak problem with fetchRequest.affectedStores #96
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @laeroah on GitHub (Nov 2, 2016).
There's a memory leak with this line:
From.swift 214: fetchRequest.affectedStores = storesThis can be reproduced on the demo app.
Since this happens every time we make a fetch, it's actually pretty serious and add up the leaked memory quickly.
Please help. Thanks.
@JohnEstropia commented on GitHub (Nov 3, 2016):
Yes we already know there is an ARC bug from
https://github.com/JohnEstropia/CoreStore/issues/100
https://github.com/JohnEstropia/CoreStore/issues/101
https://github.com/JohnEstropia/CoreStore/issues/110
So to avoid crashing right now we're choosing the lesser of two evils, erring on the side of leaks.
Please submit a bug report to Apple so that this gets fixed. (This bug existed since iOS 6, 2013)
@laeroah commented on GitHub (Nov 3, 2016):
Thanks for explaining. If I skip this line
fetchRequest.affectedStores = storesuntil it's fixed, do you see any problem there? I'm only using one persistent store in my app right now.Do you happen to know someone have already logged an issue to Apple regarding this?
@JohnEstropia commented on GitHub (Nov 3, 2016):
I tried avoiding that optimization because it will mess up iCloud stores and multi-configuration setups, but if your project just uses a single persistent store it should be fine.
Just for reference, may I know what iOS version you are seeing this?
@laeroah commented on GitHub (Nov 3, 2016):
iOS 10.0.1
@JohnEstropia commented on GitHub (Nov 3, 2016):
Can you try to put this on top of
setAffectedStoresand see if it improves a little?If you're seeing this on ListMonitor's fetch which reuses it's existing NSFetchRequest we might be able to avoid resetting the affectedStores.
@laeroah commented on GitHub (Nov 3, 2016):
No ... still see the leaks
@colinmorelli commented on GitHub (Nov 12, 2016):
@JohnEstropia If the leak is caused by the
CFBridgingRetainthat was added toCSFetchRequestinsetAffectedStores, is there any reason this can't be avoid by simply adding aCFBridgingReleasewhen either a) overwriting the affected stores with a new array, or b) in deinit/deallocEdit:
I misread how it works at first, but would it still not work to:
setAffectedStores:callCFBridgingReleaseon the current value ofaffectedStoresand
CFBridgingRetainon the provided valuedeallocto callCFBridgingReleaseon the value ofaffectedStores@JohnEstropia commented on GitHub (Nov 12, 2016):
@colinmorelli The leak only happens "sometimes". When it doesn't, the deallocation happens properly. So we are left with these options:
We can't predict when to call exactly when to call CFBridgingRetain and CFBridgingRelease because we don't know when CoreData fails to do ARC properly, and even if we do know, we can't handle it anyway because they are all internal processing.
@colinmorelli commented on GitHub (Nov 12, 2016):
Got it. That clears things up.
Well, I hate to even suggest this, but just to throw out all options, you could try to create an
NSArraysubclass, disable ARC (for the one file only), which would allow you to overrideretainandrelease, and probably detect this issue. I haven't personally tested this, but I would imagine with access to those method calls, you might be able to find out where/why this happens. Possibly even be able to figure out a workaround to it that avoids a leak.It may not work at all, but I figured I'd at least make the suggestion.
@JohnEstropia commented on GitHub (Apr 24, 2017):
I changed the ListMonitor refetch method for CoreStore v4.
53ab140341You can try it out in the
corestore4_developbranch, although some code migrations from CoreStore 3 may need to be done.@JohnEstropia commented on GitHub (Aug 23, 2017):
@laeroah Just an update, I got a follow-up from the Apple bug report that this issue was fixed on iOS 11. The workaround code that CoreStore is doing is not needed anymore (and in fact harmful) on iOS 11 devices, so this was fixed on CoreStore 4.1.1:
2912dcf010