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