It’s necessary to create before a mesh data, replace the object mesh data, and THEN delete old mesh data. If you delete the mesh data before, in some OS get an error and Blender crash.
The weird thing is that works in some OS and depending if you run in Debug or Normal mode.
You shouldn’t ever use user_clear() actually, because it will circumvent all safe guards that prevent use-after-free crashes. Instead, you should clear all references to that mesh, then delete. Finding all references is unfortunately hard.