blender+python ram problem

Hi all:

I’m developing a program in python to be read in Blender. It consists in the creation of balls in motion. The balls are created in a script that calls a second script with the dynamic. When I call the first script everything goes Ok and blender takes 200Mb from the RAM.

The problem is that if I remove everything and I run the script again, blender takes another 200Mb (+400Mb) from the RAM. So (while I’m developing the script) if I test the scritp five or six times (I have 2Gb of RAM), the system collapses. I have to close Blender (then the RAM goes to the initial value) and the process starts again.

Any idea why this is happening?

Thanks in advance!

www.enriquesahagun.es

It may be happening because your script is not managing the names of the objects it creates.
So first time through all cool it works.
Then you run it again, but the first pass still exists in memory but your script may not be examining memory to re-use existing objects so you create them again.

That is why I invented fetchIfObject function.


def fetchIfObject (passedName= ""):
    try:
        result = bpy.data.objects[passedName]
    except:
        result = None
    return result

When I make new objects, I see if they exist before I actually create them. If the object exists, it gets returned to me, and I skip the creation process and begin operations on it as if it were a new object.

Here are companion functions for curve and mesh as well.


def fetchIfCurve (passedCurveName):
    result = None
    try:
        result = bpy.data.curves[passedCurveName]
    except:
        pass
    return result

def fetchIfMesh (passedMeshName):
    result = None
    try:
        result = bpy.data.meshes[passedMeshName]
    except:
        pass
    return result

Thanks Atom:

I think the problem is that Blender does not actually remove anything until you close the program. So (exactly as you say) if I create new objects instead of using those already created, the memory usage grows indefinitely…

I’m gonna explore that idea.

Thanks!!!

Aparently I’m having a very similar problem as this one
http://blenderartists.org/forum/archive/index.php/t-128274.html

Blender doesn’t remove anything until you tell it to – which is probably a good thing…