Unloading a required file from memory [ SOLVED ]

Hi guys,

I’ve separated my UI screens into each its own file. A basic setup looks like this, which I “require” as a module:

local M = {}  
  
-- intialize function variables  
local createScreen  
  
-- required  
local thisScreen  
-- Initialization function  
local init = function( delay )  
  
 thisScreen = display.newGroup()  
  
 local delay = delay or 0  
 timer.performWithDelay( delay, createScreen)  
  
end  
M.init = init  
createScreen = function()  
  
 -- THE CODE TO BUILD UP THE SCREEN ELEMENTS GOES HERE  
  
end  
return M  

However, this works great and has no flaws. Until I start using a screen like this a second time. This could be the start screen or an options screen. All the local variables still seem to be active in the memory, and re-using a screen is now working against me.

I also tried to unrequire the file before use, using the following code :

 thisScreen = nil -- this is the variable I used to "require" the file previously  
 package.loaded["scripts.ui.createPlayer"] = nil  

Why are the variables still loaded into the memory even after I unrequire the package? [import]uid: 86582 topic_id: 28944 reply_id: 328944[/import]

Just wanted to let you all know it’s solved. I’ve been trying to get it to work all day long only to find out there was a variable set elsewhere where this module depended on. My brain got clouded! Sorry! [import]uid: 86582 topic_id: 28944 reply_id: 116571[/import]