Memory increase because of Modules?

So I tried to clear up my scripts by creating modules, but somehow it seems, that my Memory increased by 100Mb with just slightly modified code?! how can this be. What am I doing wrong? I try to make everything local…

Thanks for the Help guys, I really am stuck…

local M = {}

local function hud ()

    local hudGrp = display.newGroup()

    local timeStart =  0

    local timeFinish

    local HUDRect = display.newRect( 0,  0,  display.contentWidth,  25)

    HUDRect:setFillColor(0, 0, 0, 125)

    local lifeTxt = display.newText ( LIFE…"/"…MAXLIFE) , 30, 47, Arial, 12 )

    lifeTxt.x = 40

    lifeTxt.y = lifeTxt.y - 42

    local timeTxt = display.newText ( (“0s”) , 30, 47, Arial, 12 )

    timeTxt.x = display.contentWidth/2

    timeTxt.y = timeTxt.y - 42

    local xpTxt = display.newText ( “0xp”, 30, 47, Arial, 12 )

    xpTxt.x = display.contentWidth - 40 

    xpTxt.y = xpTxt.y - 42

    local function changeLifeTxt ( text )

        

        lifeTxt.text = text

    end

    

    M.changeLifeTxt = changeLifeTxt    

    local function changeXPTxt ( text )

        

        xpTxt.text = text

    end

    

    M.changeXPTxt = changeXPTxt    

    local function changeTimeStart ( time )

        

        timeStart = time

    end

    

    M.changeTimeStart = changeTimeStart

    local function getTimeFinish ( )

        

        return timeFinish

    end

    

    M.getTimeFinish = getTimeFinish

    local function runTime ( event )

        

        local timeEnd = event.time

        timeFinish = (math.round(math.abs((timeEnd - timeStart)/100)))/10

        --timeTxt:setReferencePoint( displayTopLeftReferencePoint )

        timeTxt.text = (timeFinish… “s”)

    end

    

    M.runTime = runTime

    hudGrp:insert( HUDRect )

    hudGrp:insert( timeTxt )

    hudGrp:insert( lifeTxt )

    hudGrp:insert( xpTxt )

    return hudGrp

end

M.hud = hud

return M

Hi.  Simply moving your code into modules should not make much difference in image/mem size of your app.  The only reason memory usage will increase (unbounded)  is if you are creating objects and not destroying them.

Also, how are you measuring this memory increase?  How you measure makes a big difference in the results you see.

I will suggest you grab my Super Meter for measuring, but I’ll also tell you if you are grabbing memory values and want a truer picture of usage, always garbage collect before measuring:

i.e. This will give you a more accurate picture for repeated measures: 

collectgarbage() -- Clear up unused mem first local postCollectMem = collectgarbage("count") 

Please note: Memory numbers grabbed without collecting first almost always present as a sawtooth wave form.  See the video at the link above at this time.

Did it jump 100mb as soon as you required it or after scene changes or reloads etc?  How did you require it and get rid of it in your main lua file?

Thanks a lot guys, but it seems that the problem I had just confused me, because when I run my app on a windows simulator it keeps telling me different memory usages than, when I am running the mac simulator or on the device itself.

Thanks roaminggamer, I am using now your Super Meter, but am wondering whether you might make a vertical version? would be very handy… thanks a lot

Hi.  Simply moving your code into modules should not make much difference in image/mem size of your app.  The only reason memory usage will increase (unbounded)  is if you are creating objects and not destroying them.

Also, how are you measuring this memory increase?  How you measure makes a big difference in the results you see.

I will suggest you grab my Super Meter for measuring, but I’ll also tell you if you are grabbing memory values and want a truer picture of usage, always garbage collect before measuring:

i.e. This will give you a more accurate picture for repeated measures: 

collectgarbage() -- Clear up unused mem first local postCollectMem = collectgarbage("count") 

Please note: Memory numbers grabbed without collecting first almost always present as a sawtooth wave form.  See the video at the link above at this time.

Did it jump 100mb as soon as you required it or after scene changes or reloads etc?  How did you require it and get rid of it in your main lua file?

Thanks a lot guys, but it seems that the problem I had just confused me, because when I run my app on a windows simulator it keeps telling me different memory usages than, when I am running the mac simulator or on the device itself.

Thanks roaminggamer, I am using now your Super Meter, but am wondering whether you might make a vertical version? would be very handy… thanks a lot