Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Unload Class from memory — Gideros Forum

Unload Class from memory

dreiko65dreiko65 Member
edited May 2015 in General questions
Hi all.
When I load a scene I "require" some classes that are related to the scene. For example:
function NewLevel:init()
-- ************************************ --
-- ************** REQUIRE ************* --
require"box2d"
require"classes/Camera"
require"classes/PhysicObjects"
...
end
Is there a way, when I change scene also to "unrequire" those classes and clean up the memory?
Or thats not how lua works and no matter what I do those classes will be always in memory?
thanks

Comments

  • piepie Member
    Accepted Answer
    @dreiko65


    this should work
    function unrequire(m)
        package.loaded[m] = nil
        _G[m] = nil
    end
     
    -- USAGE:
    --[[
        require "modulename"
        unrequire( "modulename" )
    --]]
    https://gist.github.com/jonbeebe/1195935
  • @pie thank, will try it
Sign In or Register to comment.