Memory increases with load of sprite sheet

Good day

I have a function that I loads in the same scene a new scrollView with multiple image sheet in a container every time I press a button in separate function. The texture memory gets cleared, but the memory increases every time the scrollView with new image sheet gets loaded.

1: Can one stop the memory increase? I am not to sure if it is the sprite sheet lua file that gets added to memory or the sprite sheet self that gets added to memory. 

2: Will the cards and text also be removed from memory if you clear the container layer, because it is in the container Layer?

3: Is there a way to stop the memory increase?

4: If so what is causing the memory increase?

5: Or must I not worry about the memory increase (in this scene it goes upto about 25Mbs and if I go to next scene it remains)

This is an extract of the code.

--Declare Arrays local spriteLuaArray = {} local spriteShtArray = {} local imageArray = {} local containerArray = {} local scrollView local function newScrollView (myArray) --check if scrollView exist this what I use to clear the texture memory and try do clear memory increase if scrollView ~= nil then for i = 1,#spriteShtArray do package.loaded[spriteLuaArray[i]] = nil --remove the required sprite spriteLuaArray[i] = nil --remove the Lua files loaded spriteShtArray[i] = nil --remove the spriteSheet files loaded imageArray[i]:removeSelf () --remove the individual sprite animations loaded imageArray[i] = nil end spriteLuaArray = {} --init the array spriteShtArray = {} --init the array frameCntArray = {} --init the array imageArray = {} --init the array containerArray = {} --init the array scrollView:removeSelf() --remove complete scrollView scrollView = nil print("remove scroll") end -- Create the widget if does not exist scrollView = widget.newScrollView( { friction = .93, top = topNameOffset, width = screenWidth, height = .8\*screenHeight-topNameOffset, leftPadding = mainGroupW, rightPadding = mainGroupW, hideBackground = true, hideScrollBar = false, verticalScrollDisabled = true, } ) local actFile for i = 1,#myArray do containerArray[i] = display.newGroup() local textObject = display.newText(containerArray[i], "", 0, 6, system.nativeFont, 20) textObject.text = myArray[i] --this sprite sheet already loaded before in scene create local cards = display.newImage(containerArray[i],allSht ,allLua:getFrameIndex( "cards")) cards.y = 115 cards.name = "cards"..i cards.tap = btnFunction cards:addEventListener("tap", cards) act file = nameActArray[i] --array created not show here spriteLua = require("ASSETS.GUI."..actFile) spriteSht = graphics.newImageSheet( "ASSETS/GUI/"..actFile..".jpg", spriteLua:getSheet() ) frameCnt = spriteLua:getFrameCount() spriteLuaArray[i] = spriteLua spriteShtArray[i] = spriteSht frameCntArray[i] = frameCnt imageArray[i] = display.newSprite(containerArray[i], spriteShtArray[i],{ start=1, count=frameCntArray[i] }) imageArray[i].y = .57\*cards.contentHeight imageArray[i]:setSequence() imageArray[i]:play() scrollView:insert(containerArray[i]) end return scrollView end function btnFunction (self) -- global function newScrollView (myArray) --this array changes with different arrays end local function scene:show( event )

  local sceneGroup = self.view 

if event.phase == “will” then

local scrollCreate = newScrollView()

sceneGroup:insert ( scrollCreate )

end

end

Hi

I was just thinking is it because my button function is global? But the problem is that I can not reference the button function and the scroll function in order since it is cross referenced, so that is why my button is global.

you can always use forward declaration to solve that problem (your use of global)

local funcA local funcB funcA = function() print("In A") funcB() end funcB = function() print("In B") end funcA()

Hi 

Thanks for the reply, is it because my function was global that the memory increases?

Will the lua sheets be cleared on garbage collection or will it clear and checking the memory use when I run the clearing of the arrays?

Regards

Hi

Just did the forward declaration on the functions, but the memory still increases. Not to sure if I am disposing of the sprite sheets the correct way as depicted in script above. If you can just reference my initial questions would be appreciated.

Regards

I wasn’t addressing your memory woes.  You effectively posted back with a new question (or confusion actually about scope and visibility).

I only answered to clarify the scope and visibility issue.

I’m not getting involved with the memory question because:

  1. It may not be a problem.  I see a lot of posts about memory and 99% of the time the measurements were done wrong or the user didn’t understand the nature of Lua+Corona memory management and saw an issue where it was normal behavior.

  2. If it is a problem, there is no real way to find the issue without the entire project.  When we’re talking about leaks and issues like that, finding the source involves scouring the user’s code for mistakes.  Seeing just a snippet or talking about it in general leads nowhere (usually).

Sorry if this wasn’t the answer you wanted.  

Tell you what.  If that code you posted is the BULK of you project and all your have besides that is config.lua, build.settings, and some assets… then package them in a ZIP/RAR/7S  file and PM me here with a link to the file.  I’ll look at it.

If however… you have a bunch of scene files etc. I have to pass.  Sorry, but I’m too busy to investigate right now.

Actually, the best way to get help on this if you have a huge project is to make a micro project with just the code you’re worried about.  Then see if you can find the issue in the smaller ‘package’.  If not, then share that package openly here via link.  Just be sure the example can be downloaded and run without making folks cut-copy-paste.

Understood.

Will see if I can create a smaller package and replicate the issue. If it persist will let you know. Thanks for the feedback up to now.

Yes this was a new post, I saw it as a different issue to the first post that you did answer and you where correct on that. Thanks. 

Regards

Hi

I was just thinking is it because my button function is global? But the problem is that I can not reference the button function and the scroll function in order since it is cross referenced, so that is why my button is global.

you can always use forward declaration to solve that problem (your use of global)

local funcA local funcB funcA = function() print("In A") funcB() end funcB = function() print("In B") end funcA()

Hi 

Thanks for the reply, is it because my function was global that the memory increases?

Will the lua sheets be cleared on garbage collection or will it clear and checking the memory use when I run the clearing of the arrays?

Regards

Hi

Just did the forward declaration on the functions, but the memory still increases. Not to sure if I am disposing of the sprite sheets the correct way as depicted in script above. If you can just reference my initial questions would be appreciated.

Regards

I wasn’t addressing your memory woes.  You effectively posted back with a new question (or confusion actually about scope and visibility).

I only answered to clarify the scope and visibility issue.

I’m not getting involved with the memory question because:

  1. It may not be a problem.  I see a lot of posts about memory and 99% of the time the measurements were done wrong or the user didn’t understand the nature of Lua+Corona memory management and saw an issue where it was normal behavior.

  2. If it is a problem, there is no real way to find the issue without the entire project.  When we’re talking about leaks and issues like that, finding the source involves scouring the user’s code for mistakes.  Seeing just a snippet or talking about it in general leads nowhere (usually).

Sorry if this wasn’t the answer you wanted.  

Tell you what.  If that code you posted is the BULK of you project and all your have besides that is config.lua, build.settings, and some assets… then package them in a ZIP/RAR/7S  file and PM me here with a link to the file.  I’ll look at it.

If however… you have a bunch of scene files etc. I have to pass.  Sorry, but I’m too busy to investigate right now.

Actually, the best way to get help on this if you have a huge project is to make a micro project with just the code you’re worried about.  Then see if you can find the issue in the smaller ‘package’.  If not, then share that package openly here via link.  Just be sure the example can be downloaded and run without making folks cut-copy-paste.

Understood.

Will see if I can create a smaller package and replicate the issue. If it persist will let you know. Thanks for the feedback up to now.

Yes this was a new post, I saw it as a different issue to the first post that you did answer and you where correct on that. Thanks. 

Regards