Remove object and clear from memory?

Hello all,

The normal way to remove an object from a scene in Blender 2.5 is to unlink it - e.g., to use bpy.ops.object.delete() or bpy.context.scene.objects.unlink()

The object then stays in memory until the file is saved, closed, and re-opened. Is there any way to forcibly remove the object from memory without saving and closing?

I’ve created a python script that adds objects to a scene in random configurations, renders the scene, deletes (unlinks) the objects, and then creates and renders a new scene. I would like to use this script to render many (>> 100) scenes, but because the objects aren’t removed from memory, the script bogs down and runs REALLY slow after ~6 scenes, because of the unlinked objects hogging memory.

So… Is there anything to be done about this? I think it’s fine that unlinking objects normally does not remove them from memory, but it seems like there should be some way to get around that default behavior in a script (when saving, quitting, and re-loading is not an option).

Thanks in advance for your help,


Excellent, thanks!

hey it may slow down cause of other reasons too

like edit history is on

but don’t remember how to turn it off

anybody remembers how to ?

happy 2.5

thanks for this thread.
here’s some work about it.

it completely removes an object from scenes and from memory (I presume) and its data whatever the type.
no more data and objects with O users when deleting an object, it should resolve most of the naming issues when appending, reappending etc

the associated materials, textures, curves, stuff etc will remain (for now)
did not tested with fake_users
works with library when link=False
could work as an object.operator will look at it

it’s crash free (there’s a potential crash in 258 see below and in the code comments)

usage :['Cube']

wipeOutObject(ob,False) # data remains

import bpy

def wipeOutObject(ob,and_data=True) :
    data =[].data
    # never wipe data before unlink the ex-user object of the scene else crash (2.58 3 770 2) 
    # so if there's more than one user for this data, never wipeOutData. will be done with the last user
    # if in the list
    if data.users > 1 :
    # odd :[]    
    # if the ob (board) argument comes from['aGroup'].objects,

    for sc in ob.users_scene :

    try :
    except : print('data.objects.remove issue with %s'
    # never wipe data before unlink the ex-user object of the scene else crash (2.58 3 770 2) 
    if and_data :

def wipeOutData(data) :
    if data.users == 0 :
        try : 
            # mesh
            if type(data) == bpy.types.Mesh :
            # lamp
            elif type(data) == bpy.types.PointLamp :
            # camera
            elif type(data) == bpy.types.Camera :
            # Text, Curve
            elif type(data) in [ bpy.types.Curve, bpy.types.TextCurve ] :
            # metaball
            elif type(data) == bpy.types.MetaBall :
            # lattice
            elif type(data) == bpy.types.Lattice :
            # armature
            elif type(data) == bpy.types.Armature :
            else :
                print('data still here : forgot %s'%type(data))

        except :
            # empty, field
            print('%s has no user_clear attribute.'
    else :
        print('%s has %s user(s) !'%(,data.users))

I run XP (sorry) and the last 2.58 available (3 770 2)
copy paste in the 2.58 console['Cube']

looks fine… and now move your mouse in the 3d view… say freeze (at least for me)

I don’t know if it has been reported, and in some way I don’t know if it’s a bug since it makes a bit sense it crashes, in a way :slight_smile: