Hey when executing this code it works perfectly the first part of it
import bpy;
oldScene = bpy.context.area.type;
print(oldScene);
bpy.context.area.type = 'OUTLINER';
bpy.ops.outliner.orphans_purge();
#it works fine till this end
bpy.context.area.type = 'TEXT_EDITOR';
After that, calling the current area.type will always return an error! Like pointing to a deleted instance or something. I don't understand so far the problem.