Skip to content
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

Memory leaks in Zipline #1423

Open
evtuhovaleksander opened this issue Aug 30, 2024 · 1 comment
Open

Memory leaks in Zipline #1423

evtuhovaleksander opened this issue Aug 30, 2024 · 1 comment

Comments

@evtuhovaleksander
Copy link

Hello

We are facing an issue that zipline leaks 500-600kb every "cycle" of usage.

Is there any examples

  • of correct usage ZiplineScope and ZiplineScoped?
  • how we must correctly close services and zipline
  • how we must correctly close services and zipline when service contains Flows?

We thought that we are doing something wrong with closing pipeline. So we downloaded current world-clock example.

  • we see continious leaks of memory
  • sometimes we see lots of messages from EventListener of leaked callbacks
  • after we close zipline and open next instance we see even more info about leaked callbacks

We modified example

//val serviceName = endpoint.generatePassByReferenceName()
val serviceName = endpoint.generatePassByReferenceName() + "____" + value.adapter.simpleName // to see what object is leaked
// to catch leak events
class LeakerLis: EventListener() {
  override fun serviceLeaked(zipline: Zipline, name: String) {
    super.serviceLeaked(zipline, name)
    println("LEAKED____$name")
  }
}
// we disabled hot reload
scope.launch(ziplineDispatcher + SupervisorJob()) {
    val loadResultFlow: LoadResult = ziplineLoader.loadOnce(
      applicationName = "world-clock",
      freshnessChecker = DefaultFreshnessCheckerNotFresh,
      manifestUrl=manifestUrl,
      initializer = { zipline: Zipline ->
        zipline.bind("WorldClockHost", host)
      },
    )
    var previousJob: Job? = null
    previousJob?.cancel()
    val result = loadResultFlow
    if (result is LoadResult.Success) {
      val zipline = result.zipline
      val presenter = zipline.take<WorldClockPresenter>("WorldClockPresenter")
      val job = launch {
        models.emitAll(presenter.models(events))
      }
      job.invokeOnCompletion {
        presenter.close()
        // TODO(jwilson): make this safe.
        zipline.close()
      }
      previousJob = job
    }
  }

After this changes we launch
and some times (even without closing zipline) we see

LEAKED____zipline/guest-8192____SuspendCallback
LEAKED____zipline/guest-8080____SuspendCallback
LEAKED____zipline/guest-7928____SuspendCallback
LEAKED____zipline/guest-8124____SuspendCallback
LEAKED____zipline/guest-8116____SuspendCallback

after closing and reopening screen we can see even more messages of that kind

sample project is at
https://github.com/evtuhovaleksander/zipline/tree/leaks_example

@evtuhovaleksander
Copy link
Author

evtuhovaleksander commented Sep 17, 2024

@JakeWharton and @swankjesse we are begging for help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant