How to refresh workspace
The solution is to delete data collections. There are plenty of collections in bpy.data which are not cleaned after deleting the object. For example if you add a camera, an entry in bpy.data.camera would be added but after deleting the camera object that entry remains that finally leads to out of memory errors. So the solution would be some thing like this:

def clear_collection(collection):
    for item in collection:
        collection.remove(item, True)

def cleanup():
    clear_collection(bpy.data.actions)
    clear_collection(bpy.data.armatures)
    clear_collection(bpy.data.brushes)
    clear_collection(bpy.data.cameras)
    clear_collection(bpy.data.groups)
    clear_collection(bpy.data.images)
    clear_collection(bpy.data.lamps)
    clear_collection(bpy.data.materials)
    clear_collection(bpy.data.meshes)
    clear_collection(bpy.data.objects)
    clear_collection(bpy.data.textures)

cleanup()