os.remove gives Permission denied error.

I am trying to delete a file from system.TemporaryDirectory but I get “Permission Denied”, the file was an image file that I displayed, however the image has removeSelf() and was set to =nil. I wonder why I cannot delete it.

i even call collectgarbage() but no good.

Seems like once you have displayed an image from disk, that file is locked forever.

If anyone knows different let me know.

I am now giving files unique names - but of course I can see the system.TemporaryDirectory is filling up on the simulator, don’t know if that will also be the case on a device. Not sure what or when that directory gets cleaned up and if I am responsible for it.

The docs state that system.TemporaryDirectory is a per-session directory, which is “cleaned up” by the OS after the app quits. Your best bet is to build and test on device, so that you can observe the behavior there.

Regarding your actual problem of deleting this file, providing the code you are using to attempt the removal of the files would be the fastest way for the community to assist.

Can we see your build settings? 

EDIT -

Never mind. I was thinking of a different thing.

I assume you’re running your project on Windows.

The Windows file locking system is a bit more aggressive.  An image file will be locked while displaying it in Corona, preventing you from overwriting or deleting it while it is being displayed.  When you remove all display objects that reference that image file and call collectgarbage(), Corona’s rendering system won’t immediately give up that file lock until a few frames later for performance reasons.  So, you’ll need to set up a timer with a very short delay after removing your display objects before attempting to delete the file.  But that should do it.

“Corona’s rendering system won’t immediately give up that file lock until a few frames later for performance reasons.” - Gold - thanks.

i even call collectgarbage() but no good.

Seems like once you have displayed an image from disk, that file is locked forever.

If anyone knows different let me know.

I am now giving files unique names - but of course I can see the system.TemporaryDirectory is filling up on the simulator, don’t know if that will also be the case on a device. Not sure what or when that directory gets cleaned up and if I am responsible for it.

The docs state that system.TemporaryDirectory is a per-session directory, which is “cleaned up” by the OS after the app quits. Your best bet is to build and test on device, so that you can observe the behavior there.

Regarding your actual problem of deleting this file, providing the code you are using to attempt the removal of the files would be the fastest way for the community to assist.

Can we see your build settings? 

EDIT -

Never mind. I was thinking of a different thing.

I assume you’re running your project on Windows.

The Windows file locking system is a bit more aggressive.  An image file will be locked while displaying it in Corona, preventing you from overwriting or deleting it while it is being displayed.  When you remove all display objects that reference that image file and call collectgarbage(), Corona’s rendering system won’t immediately give up that file lock until a few frames later for performance reasons.  So, you’ll need to set up a timer with a very short delay after removing your display objects before attempting to delete the file.  But that should do it.

“Corona’s rendering system won’t immediately give up that file lock until a few frames later for performance reasons.” - Gold - thanks.