[Bf-python] Memory bug in Bpy api
Willian Padovani Germano
wgermano at superig.com.br
Wed Jan 18 14:46:34 CET 2006
Hi,
One thing has nothing to do with the other:
Global dicts:
Each script in Blender has its own global dictionary, that gets deleted
when the script finishes executing (GUI scripts and also those who call
the file selector leave callbacks, so we postpone removing their global
dicts until they are really finished). This keeps things clean, with one
script not affected by another's namespace.
Note: among other changes, after 2.41 I plan to keep the global dicts of
script links (including space handlers) around, to make writing these
scripts easier and running them faster. Each will still have its own
global dict (that gets cleaned (deleted) when an error occurs), so no
namespace issues still.
Modules:
Python modules are not reloaded unless you specifically tell the
interpreter to do so.
To solve the problem of vars created in modules being persistent, simply
*do not use modules to store new data* -- do not do this:
import math
math.myvar = <something>
math.myfunction = f
#etc
Use the Registry dict, use a Blender text, save data as a file (the
Registry can do this for you). Storing vars in default modules like
math, etc. is like adding new vars or functions to a system library.
Besides not being a clean way to code, it also pollutes the modules that
other scripts will use. Imagine if many authors start doing this, soon
one script will change the data created by another and cause trouble.
Saving GUI buttons in modules would be even more troublesome, these
don't stay around for that long, Blender recreates buttons on every
redraw. That's why they should be created in the draw callback that you
register with Draw.Register.
--
Willian
More information about the Bf-python
mailing list