I suppose me asking ‘when will it no longer be in memory’ was a bit vague, but I was trying not to abstract the question. I’m really asking when I can count on it being swept up by garbage collection.
The issue, is that since I don’t know where this reference is kept, I don’t know when the module’s cache will actually be considered unreachable. Perhaps when there’s no references to the module script itself? I’d certainly hope so.
I’ll do some testing around in order to get something more definitive. Thanks for giving it a shot anyway. (If anyone knows for sure in the meantime, feel free to say as much lol)
As far as I know, the cached result from a module script is per-module, Roblox will save this return in the loaded global state, which makes it permament until the GC is allowed to purge it.
If the ModuleScript (or any references to the object it returns) remains in the game/memory, it will remain there as this is generally how the GC works.
From an outsider looking in, without being able to control memory. No, you cant release a ModuleScript’s cached result unless it’s been destroyed, and everything has dropped it’s returned value (if it’s a table or function).