1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Merge pull request #185 from jeangovil/fix-memory-leak

Remove schedulers and widgets from memory after any live-reloading
This commit is contained in:
Chris Cummer 2018-06-07 21:35:52 -07:00 committed by GitHub
commit 46978fdc8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 0 deletions

8
wtf.go
View File

@ -121,6 +121,8 @@ func watchForConfigChanges(app *tview.Application, configFlag string, grid *tvie
select {
case <-watch.Event:
loadConfig(configFlag)
// Disable all widgets to stop scheduler goroutines and rmeove widgets from memory.
disableAllWidgets()
makeWidgets(app, pages)
grid = buildGrid(Widgets)
pages.AddPage("grid", grid, true, true)
@ -155,6 +157,12 @@ var (
version = "dev"
)
func disableAllWidgets() {
for _, widget := range Widgets {
widget.Disable()
}
}
func addWidget(app *tview.Application, pages *tview.Pages, widgetName string) {
// Always in alphabetical order
switch widgetName {

View File

@ -3,4 +3,5 @@ package wtf
type Enabler interface {
Disabled() bool
Enabled() bool
Disable()
}

View File

@ -61,6 +61,10 @@ func (widget *TextWidget) Enabled() bool {
return widget.enabled
}
func (widget *TextWidget) Disable() {
widget.enabled = false
}
func (widget *TextWidget) Focusable() bool {
return widget.enabled && widget.focusable
}