Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2010-06-11 01:31:39 +0400
committerCampbell Barton <ideasman42@gmail.com>2010-06-11 01:31:39 +0400
commit1022ec3fe4b5c7491eaf271652dd7b64a7355224 (patch)
tree8e22558a4a815b3a48e3092cd2cc4d7567718bbf /release
parent6aaf55eee5a2a7fb4482ecb5eead0b3b92e24caa (diff)
clear python console namespace when used with a new window manager, otherwise old python objects are kept around between opening different blend files (leaking memory).
ideally loading a new file would clear the namespace but practically its unliekly to be a problem.
Diffstat (limited to 'release')
-rw-r--r--release/scripts/op/console_python.py21
1 files changed, 12 insertions, 9 deletions
diff --git a/release/scripts/op/console_python.py b/release/scripts/op/console_python.py
index 385dd832537..83a3130f80e 100644
--- a/release/scripts/op/console_python.py
+++ b/release/scripts/op/console_python.py
@@ -33,7 +33,7 @@ def get_console(console_id):
'''
helper function for console operators
currently each text datablock gets its own
- console - bpython_code.InteractiveConsole()
+ console - code.InteractiveConsole()
...which is stored in this function.
console_id can be any hashable type
@@ -44,21 +44,24 @@ def get_console(console_id):
if consoles is None:
consoles = get_console.consoles = {}
+ else:
+ # check if clearning the namespace is needed to avoid a memory leak.
+ # the window manager is normally loaded with new blend files
+ # so this is a reasonable way to deal with namespace clearing.
+ # bpy.data hashing is reset by undo so cant be used.
+ hash_prev = getattr(get_console, "consoles_namespace_hash", 0)
+ hash_next = hash(bpy.context.manager)
- # clear all dead consoles, use text names as IDs
- # TODO, find a way to clear IDs
- '''
- for console_id in list(consoles.keys()):
- if console_id not in bpy.data.texts:
- del consoles[id]
- '''
+ if hash_prev != hash_next:
+ get_console.consoles_namespace_hash = hash_next
+ consoles.clear()
console_data = consoles.get(console_id)
if console_data:
console, stdout, stderr = console_data
- # XXX, bug in python 3.1.2 ?
+ # XXX, bug in python 3.1.2 ? (worked in 3.1.1)
# seems there is no way to clear StringIO objects for writing, have to make new ones each time.
import io
stdout = io.StringIO()