Removing files from memory

Suppose I want to load information from a file (like I do when I require(“physics”)) and run a function or two from it that just returns key information (so that the file doesn’t stay in memory or exist in the main.lua file) and then after I’m done I want to release the file information from memory. How do I do it? So in other words, I want to have the program load a file, run a function contained in it ( a large function) and get some stuff, then close the file and remove its use from memory (I will not be returning to the file again and don’t want it chewing up memory).

Similarly, is there any good information on storing data into a file and then retrieving it later? I know it can be done and I haven’t looked up the information yet. Mostly I just hope this can also be treated the same way, or that I can store the information in some form and then just take it right back without any real effort.

(Note: if the second idea works easily, then I could just make the files this way and then it would be easier to load the data–which is basically what this idea is trying to do–load information not contained in the main file) [import]uid: 60706 topic_id: 10293 reply_id: 310293[/import]

I do not believe you can remove a file from memory.

If you have a function that is a run once and done forever type…I believe you can assign the function to an object.

myFunctionToRunOnce = function theFunction()
– function contents
end

then later on…nil out the function.

myFunctionToRunOnce = nil [import]uid: 9492 topic_id: 10293 reply_id: 37561[/import]

The only problem is that I don’t want the function stored in main.lua.

So there are data files, which I can load and close (removing them from memory by doing so), which is nice and simple enough. But if these functions aren’t initialized unless I tell it to, then your suggestion may work really well. Do you know if a function takes up significantly more memory than the lines of code that represent it? [import]uid: 60706 topic_id: 10293 reply_id: 37654[/import]

I think I found something that would work. What I did is I opened a function, had it call the require command and assign it to a local variable, ran another function or two in this function which gathered the data, and then since all the variables used in the function are local, they are removed from memory when the function closes. I think that works, but since there is no way to have Corona tell you how much memory is being used, I really have no way of knowing. [import]uid: 60706 topic_id: 10293 reply_id: 37807[/import]