Partially fix tab close memory leak

This commit is contained in:
BasioMeusPuga
2018-03-22 19:06:16 +05:30
parent e6eb056ec6
commit 42b655862c
4 changed files with 20 additions and 17 deletions

View File

@@ -17,6 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import gc
import sys
import hashlib
import pathlib
@@ -526,7 +527,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
# Update the database in the background
self.thread = BackGroundBookDeletion(
delete_hashes, self.database_path, self)
delete_hashes, self.database_path)
self.thread.finished.connect(self.move_on)
self.thread.start()
@@ -647,7 +648,10 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.thread.start()
self.tabWidget.widget(tab_index).update_last_accessed_time()
self.tabWidget.removeTab(tab_index)
self.tabWidget.widget(tab_index).deleteLater()
self.tabWidget.widget(tab_index).setParent(None)
gc.collect()
def set_toc_position(self, event=None):
current_tab = self.tabWidget.widget(self.tabWidget.currentIndex())
@@ -773,7 +777,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
# New tabs are created here
# Initial position adjustment is carried out by the tab itself
file_data = contents[i]
Tab(file_data, self.tabWidget)
Tab(file_data, self)
if self.settings['last_open_tab'] == 'library':
self.tabWidget.setCurrentIndex(0)

View File

@@ -32,7 +32,7 @@ from resources import settingswindow
class SettingsUI(QtWidgets.QDialog, settingswindow.Ui_Dialog):
def __init__(self, parent):
def __init__(self, parent=None):
super(SettingsUI, self).__init__()
self.setupUi(self)
self._translate = QtCore.QCoreApplication.translate
@@ -216,7 +216,7 @@ class SettingsUI(QtWidgets.QDialog, settingswindow.Ui_Dialog):
# Traverse directories looking for files
self.parent.statusMessage.setText(
self._translate('SettingsUI', 'Checking library folders'))
self.thread = BackGroundBookSearch(data_pairs, self)
self.thread = BackGroundBookSearch(data_pairs)
self.thread.finished.connect(self.finished_iterating)
self.thread.start()

View File

@@ -44,12 +44,12 @@ class BackGroundTabUpdate(QtCore.QThread):
class BackGroundBookAddition(QtCore.QThread):
def __init__(self, file_list, database_path, addition_mode, parent=None):
def __init__(self, file_list, database_path, addition_mode, main_window, parent=None):
super(BackGroundBookAddition, self).__init__(parent)
self.file_list = file_list
self.parent = parent
self.database_path = database_path
self.addition_mode = addition_mode
self.main_window = main_window
self.prune_required = True
if self.addition_mode == 'manual':
@@ -60,21 +60,20 @@ class BackGroundBookAddition(QtCore.QThread):
self.file_list,
('addition', self.addition_mode),
self.database_path,
self.parent.settings['auto_tags'],
self.parent.temp_dir.path())
self.main_window.settings['auto_tags'],
self.main_window.temp_dir.path())
parsed_books = books.initiate_threads()
self.parent.lib_ref.generate_model('addition', parsed_books, False)
self.main_window.lib_ref.generate_model('addition', parsed_books, False)
database.DatabaseFunctions(self.database_path).add_to_database(parsed_books)
if self.prune_required:
self.parent.lib_ref.prune_models(self.file_list)
self.main_window.lib_ref.prune_models(self.file_list)
class BackGroundBookDeletion(QtCore.QThread):
def __init__(self, hash_list, database_path, parent=None):
super(BackGroundBookDeletion, self).__init__(parent)
self.parent = parent
self.hash_list = hash_list
self.database_path = database_path
@@ -86,7 +85,6 @@ class BackGroundBookDeletion(QtCore.QThread):
class BackGroundBookSearch(QtCore.QThread):
def __init__(self, data_list, parent=None):
super(BackGroundBookSearch, self).__init__(parent)
self.parent = parent
self.valid_files = []
# Filter for checked directories

View File

@@ -41,15 +41,16 @@ from lector.sorter import resize_image
class Tab(QtWidgets.QWidget):
def __init__(self, metadata, parent=None):
def __init__(self, metadata, main_window, parent=None):
super(Tab, self).__init__(parent)
self._translate = QtCore.QCoreApplication.translate
self.parent = parent
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.main_window = main_window
self.metadata = metadata # Save progress data into this dictionary
self.are_we_doing_images_only = self.metadata['images_only']
self.is_fullscreen = False
self.main_window = self.window()
self.masterLayout = QtWidgets.QHBoxLayout(self)
self.masterLayout.setContentsMargins(0, 0, 0, 0)
@@ -152,7 +153,7 @@ class Tab(QtWidgets.QWidget):
self.horzLayout.addWidget(self.contentView)
self.horzLayout.addWidget(self.dockWidget)
title = self.metadata['title']
self.parent.addTab(self, title)
self.main_window.tabWidget.addTab(self, title)
# Hide mouse cursor timer
self.mouse_hide_timer = QtCore.QTimer()