Skip to content

Commit

Permalink
memory leak fix (no no no)
Browse files Browse the repository at this point in the history
  • Loading branch information
dertwist committed Aug 3, 2024
1 parent ceb4a14 commit 626831b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
8 changes: 8 additions & 0 deletions BatchCreator/BatchCreator_mini_windows_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class CustomFileSystemModel(QFileSystemModel):
NAME_COLUMN = 0
SIZE_COLUMN = 1
CACHE_LIMIT = 100 # Set a limit for the cache size

def __init__(self, parent=None):
super().__init__(parent)
Expand All @@ -28,8 +29,15 @@ def data(self, index, role):
if not self.isDir(index):
file_name = QFileInfo(file_name).completeBaseName()
self._cache[file_path] = file_name
if len(self._cache) > self.CACHE_LIMIT:
self._clean_cache() # Clean up the cache if it exceeds the limit
return file_name
return super().data(index, role)

def _clean_cache(self):
# Implement logic to clean up the cache, for example, removing the oldest entries
# Here you can decide how to clean up the cache based on your requirements
self._cache = {} # Resetting the cache in this example
def supportedDropActions(self):
return Qt.MoveAction

Expand Down
13 changes: 5 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys, os, subprocess, threading, portalocker, tempfile, webbrowser, time, socket
from PySide6.QtWidgets import QApplication, QWidget, QSystemTrayIcon, QMenu, QMessageBox
import sys, os, threading, portalocker, tempfile, webbrowser, time, socket, logging
from PySide6.QtWidgets import QApplication, QWidget, QSystemTrayIcon, QMenu
from PySide6.QtGui import QIcon, QAction
from ui_form import Ui_Widget
from qt_styles.qt_global_stylesheet import QT_Stylesheet_global
Expand All @@ -26,10 +26,7 @@

app_version = '1.2.1'
batchcreator_version = '1.0.0'


class Widget(QWidget):

def __init__(self, parent=None):
super().__init__(parent)
self.ui = Ui_Widget()
Expand Down Expand Up @@ -111,18 +108,18 @@ def selected_addon_name(self):

# Clean up SoundEventEditorMainWidget
try:
if self.SoundEventEditorMainWidget:
if hasattr(self, 'SoundEventEditorMainWidget') and self.SoundEventEditorMainWidget:
self.SoundEventEditorMainWidget.deleteLater()
except Exception as e:
print(f"Error while cleaning up SoundEventEditorMainWidget: {e}")

# Create a new instance of SoundEventEditorMainWidget
# # Check if the current tab is the soundeditor_tab
self.SoundEventEditorMainWidget = SoundEventEditorMainWidget()
self.ui.soundeditor_tab.layout().addWidget(self.SoundEventEditorMainWidget)

# Clean up BatchCreator_MainWindow
try:
if self.BatchCreator_MainWindow:
if hasattr(self, 'BatchCreator_MainWindow') and self.BatchCreator_MainWindow:
self.BatchCreator_MainWindow.deleteLater()
self.BatchCreator_MainWindow = None
except Exception as e:
Expand Down

0 comments on commit 626831b

Please sign in to comment.