Open greenerchen opened 3 weeks ago
Try to add ViewHosting.expel()
at the end of the sut.on(\.resultViewDidAppear)
inspection closure. Also, you might find it more convenient to use async inspection, as it handles the view expelling implicitly
Adding ViewHosting.expel()
at the end of the sut.on(\.resultViewDidAppear)
inspection closure works! async inspection looks nice. I'll give it a shot. Thank you!! :D
Just put a note here. After I use async inspection instead, it requires more resource to compile on my CI service (Bitrise M1 medium 4 CPU @ 3.2GHz, 6 GB RAM). With Bitrise Support's help, we've tested it needs Bitrise M1 Large 8 CPU @ 3.2GHz, 12 GB RAM) to compile successfully. Seems I can try another CI service.
I glanced the source code of ViewHosting.expel()
, and found the design is to test and expel a single view. For my case, it was testing a NavigationStack's destination view. Seems this is the root cause why I encountered memory leaks.
@greenerchen since you've reopened the ticket - what do you think should be done here? I thought after you added view expelling the memory issue was gone
@nalexn yes, the memory issue was gone on my laptop after I added view expelling. I wanna help update document about async inspection with NavigationDestination, so I reopened the ticket for the record.
Hi,
I'm learning SwiftUI, Swift concurrency, and trying TDD using ViewInspector. I use the code snippet[1] to detect possible memory leaks in my unit tests, and I found that the
@ObservedObject
property couldn't be released after test teardown.@ObservedObject
property implies it's a MainActor instance, so my tests all annotate@MainActor
to suppress the warnings of actor-isolated messages. I'm curious if I did the test wrong and how I can fix it. Thanks!code snippets
View using
@ObservedObject
The test