I suggest checking out
Lua 5.1 Reference Manual - collectgarbageYou can use it to monitor how much memory lua is using or force garbage collection, as well as tuning other GC parameters. The lua garbage collector doesn't know how much memory is available, so it is possible to run out of memory despite most of it being used by collectible objects.
As a general rule, you should pass multiple values to print and write instead of using concatenation. Eg, instead of
print(currentFile.."|"..fileCreatedDate..".JPG")
use
print(currentFile,"|",fileCreatedDate,".JPG")
See this post
Night-time time-lapseAs I advised you earlier in
String lib! you should use sleep instead of a busy loop. It is possible (even likely) that your issue is still CPU starvation rather than memory. You can get 10ms resolution from os.time or get_tick_count, which should be plenty for your purposes! If you don't want to calculate the correct sleep (which really isn't that hard) just sleep for 100ms every iteration or something like that. Or at least make sure you sleep after every shoot, since I already verified that not doing so causes crashes. (yes, the fact that you can hit CPU starvation issues is a bug, but for the moment you'll have to work around it.)
If you do insist on using a busy loop, writing to your logfile every single iteration is probably not a great idea either.
Local vs global shouldn't be an issue here, although locals are generally more efficient, so it's still a good idea to use them.