# How to remove Mesh Data of a Blend File?

Hi recently I was working with big files in a Blend file now I decided to separate the Objects so well I was able to do that but now I just have one object. But I have a lot of mesh Data.

As you can see I only have one Object in the scene called "Banquita" but It seems that I have A lot of "Meshes Data" inside the Blend file that increases a lot the size.

I already check DataBlocks but there's not option for this, delete the Mesh Data.

• If the mesh data is not used anywhere else it is erased automatically by Blender, you just have to save the file and reopen for it to actually be gone though. So It will stick around until you close and reopen Blender. Also check if you didn't press the 'F' Fake User button for those datablocks, that will make blender save those datablocks even if they have no users – Duarte Farrajota Ramos Oct 25 '16 at 0:41
• Ok know I know why I can't delete that. But now how can you set 0 users to the data mesh ? An image is easy shift + x to the image in the editor but here I only was able to set just one user, but I need 0 – Hammerh5 Oct 25 '16 at 1:54
• If the mesh data still has users just delete the respective objects (check if they are not in a different scene. Otherwise if they all have fake users it might just be easier to import the one you want into a new blend file than erase all the unwanted ones manually – Duarte Farrajota Ramos Oct 25 '16 at 2:13
• Yep I even try to write a script is more easy to create a new blend file and import the objects. Thanks – Hammerh5 Oct 25 '16 at 5:02

Well it was more easy than I thought. Just go to the Outliner, change to the Blender File. There you can see all the data of the actual .blend file

Select all the unwanted meshes and right click Delete . That's all.

When you delete an object, not all information about it will be deleted. Its mesh data will remain in the file.

Of course, you can try to delete this data one by one, or try to re-open the file several times, but there is a way more simple:

So if you want to delete the unused mesh data, open Outliner in Orphan data mode and click on Purge All - it will delete all mesh data that are not used in the scene.

You can remove all unlinked data blocks as follow if you are willing to use Blender's Python API. This way you can make sure there will never be any memory leakage what so ever. You can execute the following code after you load each object or every couple of times (say every 10 objects).

First remove the meshes/objects with the following code:

for obj in bpy.context.scene.objects:
if obj.type == 'MESH':
obj.select = True
else:
obj.select = False
bpy.ops.object.delete()


where you can check type against any of the following values according to [this documentation][1]:

[‘MESH’, ‘CURVE’, ‘SURFACE’, ‘META’, ‘FONT’, ‘ARMATURE’, ‘LATTICE’, ‘EMPTY’, ‘CAMERA’, ‘LAMP’, ‘SPEAKER’]


Then you can execute the following code snippet to remove all the unused blocks. This way you don't have to close/open Blender or save/open a .blend file:

for block in bpy.data.meshes:
if block.users == 0:
bpy.data.meshes.remove(block)

for block in bpy.data.materials:
if block.users == 0:
bpy.data.materials.remove(block)

for block in bpy.data.textures:
if block.users == 0:
bpy.data.textures.remove(block)

for block in bpy.data.images:
if block.users == 0:
bpy.data.images.remove(block)


IMPORTANT NOTE: It looks like that there is some dependencies between some data blocks such as mesh, texture, image and materials. If you do not remove the data blocks on the highest level of the hierarchy, you will not be able to remove other data blocks or you have to take the risk and remove data blocks with users more than 0. So make sure you use the code above in the following order to remove data blocks. This way you can remove all unlinked (users == 0) data blocks:

remove meshes --> remove materials --> remove textures --> remove images

The followings also have data blocks:

bpy.data.curves
bpy.data.lamps
bpy.data.cameras

• This is more relevant to how you can prevent memory leakage in Blender – Amir Mar 1 '18 at 4:13