Skip to content

Commit

Permalink
Merge pull request #7234 from dalthviz/fixes_issue_7157
Browse files Browse the repository at this point in the history
PR: Call garbage collector from Main Window after closing Variable Explorer editors
  • Loading branch information
ccordoba12 authored Jun 7, 2018
2 parents 604d8ff + 58386fc commit 1c4d9d5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
5 changes: 5 additions & 0 deletions spyder/app/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import atexit
import errno
import gc
import os
import os.path as osp
import re
Expand Down Expand Up @@ -1954,6 +1955,10 @@ def show_toolbars(self):
self._update_show_toolbars_action()

# --- Other
def free_memory(self):
"""Free memory after event."""
gc.collect()

def plugin_focus_changed(self):
"""Focus has changed from one plugin to another"""
self.update_edit_menu()
Expand Down
16 changes: 14 additions & 2 deletions spyder/plugins/variableexplorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""Variable Explorer Plugin"""

# Third party imports
from qtpy.QtCore import Signal, Slot
from qtpy.QtCore import QTimer, Signal, Slot
from qtpy.QtWidgets import QGroupBox, QStackedWidget, QVBoxLayout, QWidget

# Local imports
Expand Down Expand Up @@ -60,6 +60,8 @@ class VariableExplorer(QWidget, SpyderPluginMixin):
"""
CONF_SECTION = 'variable_explorer'
CONFIGWIDGET_CLASS = VariableExplorerConfigPage
INITIAL_FREE_MEMORY_TIME_TRIGGER = 60 * 1000 # ms
SECONDARY_FREE_MEMORY_TIME_TRIGGER = 180 * 1000 # ms
sig_option_changed = Signal(str, object)

def __init__(self, parent):
Expand Down Expand Up @@ -114,6 +116,15 @@ def change_option(self, option_name, new_value):
new_value = new_value[1:]
self.sig_option_changed.emit(option_name, new_value)

@Slot()
def free_memory(self):
"""Free memory signal."""
self.main.free_memory()
QTimer.singleShot(self.INITIAL_FREE_MEMORY_TIME_TRIGGER,
lambda: self.main.free_memory())
QTimer.singleShot(self.SECONDARY_FREE_MEMORY_TIME_TRIGGER,
lambda: self.main.free_memory())

# ----- Stack accesors ----------------------------------------------------
def set_current_widget(self, nsb):
self.stack.setCurrentWidget(nsb)
Expand Down Expand Up @@ -144,6 +155,7 @@ def add_shellwidget(self, shellwidget):
nsb.set_shellwidget(shellwidget)
nsb.setup(**self.get_settings())
nsb.sig_option_changed.connect(self.change_option)
nsb.sig_free_memory.connect(self.free_memory)
self.add_widget(nsb)
self.shellwidgets[shellwidget_id] = nsb
self.set_shellwidget_from_id(shellwidget_id)
Expand Down Expand Up @@ -203,7 +215,7 @@ def get_plugin_actions(self):
def register_plugin(self):
"""Register plugin in Spyder's main window"""
self.main.add_dockwidget(self)

def apply_plugin_settings(self, options):
"""Apply configuration file's plugin settings"""
for nsb in list(self.shellwidgets.values()):
Expand Down
7 changes: 5 additions & 2 deletions spyder/widgets/variableexplorer/collectionseditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ def setData(self, index, value, role=Qt.EditRole):

class CollectionsDelegate(QItemDelegate):
"""CollectionsEditor Item Delegate"""
sig_free_memory = Signal()

def __init__(self, parent=None):
QItemDelegate.__init__(self, parent)
Expand Down Expand Up @@ -579,7 +580,7 @@ def editor_rejected(self, editor_id):

def free_memory(self):
"""Free memory after closing an editor."""
gc.collect()
self.sig_free_memory.emit()

def commitAndCloseEditor(self):
"""Overriding method commitAndCloseEditor"""
Expand Down Expand Up @@ -657,7 +658,8 @@ class BaseTableView(QTableView):
sig_option_changed = Signal(str, object)
sig_files_dropped = Signal(list)
redirect_stdio = Signal(bool)

sig_free_memory = Signal()

def __init__(self, parent):
QTableView.__init__(self, parent)
self.array_filename = None
Expand Down Expand Up @@ -1473,6 +1475,7 @@ def __init__(self, parent, data, minmax=False,
self.setModel(self.model)
self.delegate = RemoteCollectionsDelegate(self, get_value_func,
set_value_func)
self.delegate.sig_free_memory.connect(self.sig_free_memory.emit)
self.setItemDelegate(self.delegate)

self.setup_table()
Expand Down
4 changes: 3 additions & 1 deletion spyder/widgets/variableexplorer/namespacebrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class NamespaceBrowser(QWidget):
"""Namespace browser (global variables explorer widget)"""
sig_option_changed = Signal(str, object)
sig_collapse = Signal()

sig_free_memory = Signal()

def __init__(self, parent):
QWidget.__init__(self, parent)

Expand Down Expand Up @@ -139,6 +140,7 @@ def setup(self, check_all=None, exclude_private=None,

self.editor.sig_option_changed.connect(self.sig_option_changed.emit)
self.editor.sig_files_dropped.connect(self.import_data)
self.editor.sig_free_memory.connect(self.sig_free_memory.emit)

# Setup layout
blayout = QHBoxLayout()
Expand Down

0 comments on commit 1c4d9d5

Please sign in to comment.