Ok so it works, and well.
The problem now resides in the size of the file / the nuber of paths.
I got over 500k objects.
The loop goes through each one of then to find out if it's a valid object to delete. Of course this overwhelms the memory and eventually fails before going through everything.
SO since this works, I can do a selection by appearance, as suggested by Larry, copy that selection in a file, run the script, copy whatever is left back in the original and voila! A nice clean plan!
Thank you for you help, it's really appreciated!
Ugo