Originally created by @jamesbebbington on GitHub (Mar 29, 2016).
After having upgraded from CoreStore v1.4.4 to v1.6.1 I'm getting a repeatable crash when my ListMonitor is deinitialized when the controller it is a property of is deallocated:
My ListMonitor is instantiated like so:
classProjectController:UITableViewController,ListSectionObserver,TableViewDisabling{…varproject:Project?{didSet{guardletproject=self.projectelse{return}questions.refetch(Where("project.id == %d",project.id))}}/// Questions monitorletquestions=CoreStore.monitorSectionedList(From(Question),SectionBy("category.name"),OrderBy(.Ascending("position")),Where(false)// Overridden in .project property observer)…}
Explicitly removing the observer when the controller is deallocated doesn't help.
I'm not sure how to go about debugging this one, could you give me some pointers please.
Thanks.
Originally created by @jamesbebbington on GitHub (Mar 29, 2016).
After having upgraded from CoreStore v1.4.4 to v1.6.1 I'm getting a repeatable crash when my `ListMonitor` is deinitialized when the controller it is a property of is deallocated:
<img width="961" alt="screen shot 2016-03-29 at 10 40 30" src="https://cloud.githubusercontent.com/assets/5934/14104037/e64983ac-f59a-11e5-9819-52e5cdd36298.png">
My `ListMonitor` is instantiated like so:
``` swift
class ProjectController: UITableViewController, ListSectionObserver, TableViewDisabling {
…
var project: Project? {
didSet {
guard let project = self.project else { return }
questions.refetch(Where("project.id == %d", project.id))
}
}
/// Questions monitor
let questions = CoreStore.monitorSectionedList(
From(Question),
SectionBy("category.name"),
OrderBy(.Ascending("position")),
Where(false) // Overridden in .project property observer
)
…
}
```
Explicitly removing the observer when the controller is deallocated doesn't help.
I'm not sure how to go about debugging this one, could you give me some pointers please.
Thanks.
@jamesbebbington commented on GitHub (Mar 29, 2016):
Nope, no tweaking.
It might be also worth noting that this affected me both before and after the upgrade to swift 2.2.
@jamesbebbington commented on GitHub (Mar 29, 2016):
Nope, no `tweak`ing.
It might be also worth noting that this affected me both before and after the upgrade to swift 2.2.
@jamesbebbington commented on GitHub (Mar 29, 2016):
I'll double-check but if I recall correctly, the All Exceptions breakpoint made no difference either way. I also tried Enabling Zombies and the Address Sanitizer but couldn't get anything helpful in the console.
@jamesbebbington commented on GitHub (Mar 29, 2016):
I'll double-check but if I recall correctly, the All Exceptions breakpoint made no difference either way. I also tried Enabling Zombies and the Address Sanitizer but couldn't get anything helpful in the console.
The stack trace comes from deallocation of a NotificationObserver, which leads me to believe that it's a release timing problem.
@JohnEstropia commented on GitHub (Mar 29, 2016):
Can you try to add this to `ListMonitor`'s `deinit` and see if there are any improvements?
``` swift
deinit {
self.observerForWillChangePersistentStore = nil
self.observerForDidChangePersistentStore = nil
self.fetchedResultsControllerDelegate.fetchedResultsController = nil
self.isPersistentStoreChanging = false
}
```
The stack trace comes from deallocation of a `NotificationObserver`, which leads me to believe that it's a release timing problem.
@jamesbebbington commented on GitHub (Mar 29, 2016):
Here you go:
And the previous frame if that's of any help:
@jamesbebbington commented on GitHub (Mar 29, 2016):
Here you go:
<img width="1072" alt="screen shot 2016-03-29 at 21 12 25" src="https://cloud.githubusercontent.com/assets/5934/14122275/f6a5cc94-f5f2-11e5-8d42-0704aecf1c9b.png">
And the previous frame if that's of any help:
<img width="1072" alt="screen shot 2016-03-29 at 21 12 45" src="https://cloud.githubusercontent.com/assets/5934/14122303/16bb8456-f5f3-11e5-90ee-3dcc5eb2fe9e.png">
@JohnEstropia commented on GitHub (Mar 29, 2016):
@fractious Looks like a bug happening when the NSFetchRequest captured by a swift closure gets deallocated. Can you try this commit? https://github.com/JohnEstropia/CoreStore/commit/48a86947205787310f78245ceebf126506c5ebe8
@jamesbebbington commented on GitHub (Mar 29, 2016):
My dinner is frantically beeping at me now so I'll give it a whirl in a bit. Thanks for taking the time to investigate this, much appreciated. I'll let you know how I get on with it later.
@jamesbebbington commented on GitHub (Mar 29, 2016):
My dinner is frantically beeping at me now so I'll give it a whirl in a bit. Thanks for taking the time to investigate this, much appreciated. I'll let you know how I get on with it later.
Thanks! message sent to deallocated instance means there's definitely a leak somewhere. I'll try to dig through possible locations.
@JohnEstropia commented on GitHub (Mar 30, 2016):
Thanks! `message sent to deallocated instance` means there's definitely a leak somewhere. I'll try to dig through possible locations.
I'm guessing you are importing CoreStore's source files directly in your project? (without using frameworks)
One thing I noticed in your stack trace
...
@objc CoreStoreFetchedResultsController
...
CoreStoreFetchedResultsController is being marked as @objc, which normally wouldn't happen if built as a framework. That in itself is not a problem, but the deallocation behavior probably is different so that's why I can't reproduce it on my side.
@JohnEstropia commented on GitHub (Mar 30, 2016):
I'm guessing you are importing CoreStore's source files directly in your project? (without using frameworks)
One thing I noticed in your stack trace
```
...
@objc CoreStoreFetchedResultsController
...
```
CoreStoreFetchedResultsController is being marked as `@objc`, which normally wouldn't happen if built as a framework. That in itself is not a problem, but the deallocation behavior probably is different so that's why I can't reproduce it on my side.
Anyway try out the commit here: https://github.com/JohnEstropia/CoreStore/commit/633ab0a2498ebc655f6f75d5d93e35c4251f05f0
If it works for you I'll update the master branch.
I'll get back to you about that latest commit in about 30 mins.
Cheers.
@jamesbebbington commented on GitHub (Mar 30, 2016):
Actually I'm using cocoapods, my `Podfile` begins:
```
source 'https://github.com/CocoaPods/Specs'
platform :ios, '8.0'
use_frameworks!
…
```
I'll get back to you about that latest commit in about 30 mins.
Cheers.
@jamesbebbington commented on GitHub (Mar 30, 2016):
So 633ab0a249 crashes in CoreStoreFetchedResultsController:
This is with zombies enabled, nothing is printed to the console
@jamesbebbington commented on GitHub (Mar 30, 2016):
So 633ab0a2498ebc655f6f75d5d93e35c4251f05f0 crashes in `CoreStoreFetchedResultsController`:
<img width="1072" alt="screen shot 2016-03-30 at 15 20 21" src="https://cloud.githubusercontent.com/assets/5934/14145247/13f94dd2-f68b-11e5-95f3-2caf4732dd95.png">
This is with zombies enabled, nothing is printed to the console
Ookaay... if it's not the delegate that's leaking then this is most probably an ARC bug. I need to find the pattern that triggers it but I cannot reproduce this on my side, so if you have a project that you can send to me that would definitely help.
@JohnEstropia commented on GitHub (Mar 31, 2016):
Ookaay... if it's not the delegate that's leaking then this is most probably an ARC bug. I need to find the pattern that triggers it but I cannot reproduce this on my side, so if you have a project that you can send to me that would definitely help.
@jamesbebbington commented on GitHub (Mar 31, 2016):
Thanks John, I'll see if I can make a minimal test case from my app. Where do you want me to send it?
EDIT: An email address please, so I can create you a login to pull down some test data. Thanks.
@jamesbebbington commented on GitHub (Mar 31, 2016):
Thanks John, I'll see if I can make a minimal test case from my app. Where do you want me to send it?
EDIT: An email address please, so I can create you a login to pull down some test data. Thanks.
@JohnEstropia commented on GitHub (Mar 31, 2016):
Thanks for the test app! I found the culprit and it seems to be an old Core Data bug: http://stackoverflow.com/questions/14396375/nsfetchedresultscontroller-crashes-in-ios-6-if-affectedstores-is-specified
Seems fixable with an NSFetchRequest subclass (https://github.com/JohnEstropia/CoreStore/commit/0b24072259afdabb9157cd5c562482c44329ba2c). Try out the develop branch, hopefully it works fine for you.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @jamesbebbington on GitHub (Mar 29, 2016).
After having upgraded from CoreStore v1.4.4 to v1.6.1 I'm getting a repeatable crash when my
ListMonitoris deinitialized when the controller it is a property of is deallocated:My
ListMonitoris instantiated like so:Explicitly removing the observer when the controller is deallocated doesn't help.
I'm not sure how to go about debugging this one, could you give me some pointers please.
Thanks.
@JohnEstropia commented on GitHub (Mar 29, 2016):
@fractious Are you using a
Tweakclause?@JohnEstropia commented on GitHub (Mar 29, 2016):
btw, is that stacktrace the stopping point of an Exception Breakpoint?
@jamesbebbington commented on GitHub (Mar 29, 2016):
Nope, no
tweaking.It might be also worth noting that this affected me both before and after the upgrade to swift 2.2.
@jamesbebbington commented on GitHub (Mar 29, 2016):
I'll double-check but if I recall correctly, the All Exceptions breakpoint made no difference either way. I also tried Enabling Zombies and the Address Sanitizer but couldn't get anything helpful in the console.
@JohnEstropia commented on GitHub (Mar 29, 2016):
Can you try to add this to
ListMonitor'sdeinitand see if there are any improvements?The stack trace comes from deallocation of a
NotificationObserver, which leads me to believe that it's a release timing problem.@jamesbebbington commented on GitHub (Mar 29, 2016):
No improvement I'm afraid:
@JohnEstropia commented on GitHub (Mar 29, 2016):
can you show me the
7 __lldb_unnamed_function6...part of the stack trace?@jamesbebbington commented on GitHub (Mar 29, 2016):
Here you go:
And the previous frame if that's of any help:
@JohnEstropia commented on GitHub (Mar 29, 2016):
@fractious Looks like a bug happening when the NSFetchRequest captured by a swift closure gets deallocated. Can you try this commit? https://github.com/JohnEstropia/CoreStore/commit/48a86947205787310f78245ceebf126506c5ebe8
@jamesbebbington commented on GitHub (Mar 29, 2016):
My dinner is frantically beeping at me now so I'll give it a whirl in a bit. Thanks for taking the time to investigate this, much appreciated. I'll let you know how I get on with it later.
@JohnEstropia commented on GitHub (Mar 29, 2016):
Sure, no problem! Thanks for the report! Weird though, we've never seen this bug before..
@jamesbebbington commented on GitHub (Mar 29, 2016):
No change I'm afraid:
@JohnEstropia commented on GitHub (Mar 30, 2016):
Aww... Can you try running with NSZombies on and see if we find something?
@jamesbebbington commented on GitHub (Mar 30, 2016):
Does this help?
@JohnEstropia commented on GitHub (Mar 30, 2016):
Thanks!
message sent to deallocated instancemeans there's definitely a leak somewhere. I'll try to dig through possible locations.@JohnEstropia commented on GitHub (Mar 30, 2016):
I'm guessing you are importing CoreStore's source files directly in your project? (without using frameworks)
One thing I noticed in your stack trace
CoreStoreFetchedResultsController is being marked as
@objc, which normally wouldn't happen if built as a framework. That in itself is not a problem, but the deallocation behavior probably is different so that's why I can't reproduce it on my side.Anyway try out the commit here: https://github.com/JohnEstropia/CoreStore/commit/633ab0a2498ebc655f6f75d5d93e35c4251f05f0
If it works for you I'll update the master branch.
@jamesbebbington commented on GitHub (Mar 30, 2016):
Actually I'm using cocoapods, my
Podfilebegins:I'll get back to you about that latest commit in about 30 mins.
Cheers.
@jamesbebbington commented on GitHub (Mar 30, 2016):
So
633ab0a249crashes inCoreStoreFetchedResultsController:This is with zombies enabled, nothing is printed to the console
@JohnEstropia commented on GitHub (Mar 31, 2016):
Ookaay... if it's not the delegate that's leaking then this is most probably an ARC bug. I need to find the pattern that triggers it but I cannot reproduce this on my side, so if you have a project that you can send to me that would definitely help.
@jamesbebbington commented on GitHub (Mar 31, 2016):
Thanks John, I'll see if I can make a minimal test case from my app. Where do you want me to send it?
EDIT: An email address please, so I can create you a login to pull down some test data. Thanks.
@JohnEstropia commented on GitHub (Mar 31, 2016):
You can find my address here https://github.com/JohnEstropia/CoreStore/blob/master/CoreStore.podspec
@JohnEstropia commented on GitHub (Mar 31, 2016):
Thanks for the test app! I found the culprit and it seems to be an old Core Data bug: http://stackoverflow.com/questions/14396375/nsfetchedresultscontroller-crashes-in-ios-6-if-affectedstores-is-specified
Seems fixable with an NSFetchRequest subclass (https://github.com/JohnEstropia/CoreStore/commit/0b24072259afdabb9157cd5c562482c44329ba2c). Try out the develop branch, hopefully it works fine for you.
@jamesbebbington commented on GitHub (Mar 31, 2016):
That seems to have done the trick! Loving your work, cheers John.
@JohnEstropia commented on GitHub (Mar 31, 2016):
Great, I'll merge to master and push the pod update then.