@soren I do not know which program flags this error: "An error occurred: Not enough memory available on the board. Synchronizing failed. Please reboot your device manually". May atom+Pymakr plugin. But besides that:
There is a difference between the free memory in the flash file system, which is reported by os.getfree("/flash"), and the RAM, which is reported by gc.free_mem(). gc.collect() only affects the RAM and performs a garbage collection there.
The error message you flag sounds more like being caused by file system problems, and maybe it's not even the free area, which is the reason, but some other file related error, which is faulty reported as "out of free space", since that is the most common reason. You could try to use simple methods like ftp and terminal emulator to upload and run your files. The visibility of what's going on is much better in case of problems
Errors allocating RAM are reported like: "MemoryError: memory allocation failed, allocating xxxx bytes".