e.g. Materials can only be removed if there are 0 users:
mat = bpy.data.materials[0]
mat.user_clear() # make it have zero users
bpy.data.materials.remove(mat) # works since mat has 0 user count
If you then enter and exit edit mode, blender may crash, since the material is still in material slot, but doesn't exist anymore.
Description
Description
Event Timeline
Comment Actions
It can indeed crash, see the documentation:
http://www.blender.org/documentation/blender_python_api_2_63_17/bpy.types.ID.html#bpy.types.ID.user_clear