[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: dofile vs require
- From: "Daniel Collins" <daniel.collins@...>
- Date: Fri, 2 Jun 2006 23:37:33 +0930
> Sure. require is just a dofile that tries to load the file
> from standard locations. It also ensures that a file is not
> loaded twice. --lhf
More than these things, it was my thought that using require may be
preventing garbage collection of my initialisation code, since the
closure created from the file is stored in package.loaded. At least that
is my understanding of it. I checked in the C code and package.loaded
does not have weak values, so it must be preventing collection. For a
package that lots of code needs to use this is probably a good thing,
but for my code that needs to run once only it might be less good,
particularly as this is running on mobile phones.
I am tempted to do something like this simply because the files live in
different locations and I like the convenience of the path searching
that require does:
require "initCode"
package.loaded["initCode"] = nil
At least this makes it explicit that the code is not required anymore.
Perhaps it would be neater thus:
function unrequire(p)
package.loaded[p] = nil
end
require "initCode"
unrequire "initCode"
- DC