-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Detect host-side node, widget, and view leaks #2254
Conversation
cc24296
to
4b6edaa
Compare
redwood-treehouse-host/src/commonMain/kotlin/app/cash/redwood/treehouse/TreehouseAppContent.kt
Outdated
Show resolved
Hide resolved
redwood-leak-detector/src/commonMain/kotlin/app/cash/redwood/leaks/LeakDetector.kt
Outdated
Show resolved
Hide resolved
"Redwood-internal widget protocol node when $cause" | ||
} | ||
|
||
// Detaching frees the node's reference to the widget, so this must be done last. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice comment!
.addModifiers(OVERRIDE) | ||
.returns(STRING) | ||
// This explicit string builder usage allows sharing of strings in dex. | ||
// See https://jakewharton.com/the-economics-of-generated-code/#string-duplication. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👨🏻🍳👌🏻
timeSource = TimeSource.Monotonic, | ||
leakThreshold = 10.seconds, | ||
listener = object : LeakListener() { | ||
override fun onReferenceLeaked( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’d like to somehow wire things together so that this is just another event to listen to in EventListener
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(And we’d need to hoist the policy up to the TreehouseApp.Factory or something)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally had this design, but it meant that the ownership of creating the LeakDetector
and running its coroutine are deep inside the code.
I think maybe the listener of whether something leaks should be supplied when you watch something. This allows the decision of whether the leak detector is real or not to be very far away from the "watch this and notify me" call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I don't think this makes sense. The EventListener is scoped to a code load. We can use that for reporting guest-side leaks, but it's not a good fit for host-side. Host-side leaks need to monitor things like the Zipline instance whose lifetime exceeds that of the EventListener. Since we null the real listener on cancel (to avoid a leak), we'd have nowhere to report actual leaks. I think for now I'm going to leave the whole LeakDetector exposed through the factory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once we get guest-side leaks, they'll come through the EventListener
.
fd2ec00
to
c47f8dc
Compare
This is ready but it's 5pm and I'm not starting a rebase. Tomorrow problem. |
830fef6
to
f5e2860
Compare
*/ | ||
public suspend fun checkLeaks() | ||
public suspend fun awaitClose() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻
|
||
leakDetector.checkLeaks() | ||
assertThat(listener.events).isEmpty() | ||
// No refs? No GC. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay negative testing
f5e2860
to
cc09030
Compare
Refs #575.
CHANGELOG.md
's "Unreleased" section has been updated, if applicable.