Hi,
I having problem in my cleaning function.
In my page there are two group one is main group and another one is temporary. Over that temporary group I have created rectangle who width is 5000 and over this rectangle I have added 25 images for sliding. but when I move to next page I remove temporary group as well as all the object which have inserted over it but still my memory is not reducing and my app is hanging on device.
At first time, when enter in screen I print memory that display textMem=62.76 and when I go to next screen again printing memory that still same.
Any help will be appreciated.
[import]uid: 75428 topic_id: 20590 reply_id: 320590[/import]
Hard to say without seeing some code, it does sound like something isn’t being cleaned up though. [import]uid: 52491 topic_id: 20590 reply_id: 80787[/import]
module(…, package.seeall)
director = require(“director”)
content = require(“content”)
–cleangroup=require(“cleangroup”)
function new()
----------------------Local Variables -----------------------------------------------
local isAndroid = “Android” == system.getInfo(“platformName”)
local isSimulator = “simulator” == system.getInfo(“environment”)
local displayWidth = display.viewableContentWidth
local displayHeight = display.viewableContentHeight
local centerX = display.contentWidth/2
local centerY = display.contentHeight/2
local isSoundComplete=true
local swipFlag=false
local backGround
local home
local paintpage = 4.1
local bcMusic
local beganX
local beganY
local endedX
local endedY
local musicon
local musicoff
local voiceon
local voiceoff
local isBackClick=false
local referenceIcon
local slash
----------------------------------------- functions----------------------------------------------
local clean
local storeScreenObjs
local removeScreenObjs
local onHomeClick
local startDrag
local loadFooterAnimals
local assignBooleanValue
----------------------------------------------- Arrays ------------------------------------------------------
–local timerStash = {}
local screenObjs={}
–local tid={}
-------------- – we store everything inside this group at the end
local learnScreen = display.newGroup()
local rectGroup = display.newGroup()
clean = function()
audio.stop(0)
home:removeEventListener(“tap”, onHomeClick)
removeScreenObjs()
learnScreen:remove(backGround)
backGround=nil
learnScreen:remove(home)
home=nil
learnScreen:remove(voiceon)
voiceon=nil
learnScreen:remove(voiceoff)
voiceoff=nil
learnScreen:remove(musicon)
musicon=nil
learnScreen:remove(musicoff)
musicoff=nil
imgSound=nil
bcMusic=nil
learnScreen:remove(rectGroup)
rectGroup=nil
learnScreen:remove(referenceIcon)
referenceIcon=nil
learnScreen:remove(slash)
slash=nil
end
storeScreenObjs = function(obj)
screenObjs[#screenObjs+1] = obj
end
removeScreenObjs = function()
local k
for k = 1,#screenObjs do
learnScreen:remove(screenObjs[k])
screenObjs[k]=screenObjs[k-1]
screenObjs[k] = nil
end
screenObjs={}
end
onHomeClick = function()
clean()
isBackClick=true
director:changeScene(“menu”, “crossFade”)
end
loadFooterAnimals = function()
local img
local tempx = 100
for i = 1, 25 do
img = display.newImageRect( content[1].animal[i]…".png", 576, 352)
img.name = content[1].animal[i]
img.xScale = .3
img.yScale = .3
img.alpha=0.5
img.x = tempx
img.y = 705–650
img:addEventListener(“tap”, onloadTapPage)
storeScreenObjs(img)
rectGroup:insert(img)
tempx = tempx + 180
end
learnScreen:insert(rectGroup)
end
startDrag = function( event )
local t = event.target
local phase = event.phase
if “began” == phase then
–display.getCurrentStage():setFocus( t )
t.isFocus = true
t.x0 = event.x - t.x
t.y0 = event.y - t.y
startdragx = event.x
startgroupx = rectGroup.x
elseif t.isFocus then
if “moved” == phase then
rectGroup.x = startgroupx-(startdragx-event.x)
elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
local wopage = (-rectGroup.x) / 870
local newxi = math.round( wopage )
if (newxi > paintpage) then newxi = paintpage end
if (newxi < 0) then newxi = 0 end
tid[#tid+1]=transition.to( rectGroup, { x = -(newxi*870), time = 400 } )
end
end
return true
end
----------------------------- Start screen loading------------------------------------------------------------
display.setStatusBar( display.HiddenStatusBar )
backGround = display.newImageRect( “animalsfeaturedinquran.png”, displayWidth, displayHeight)
backGround.x = centerX
backGround.y = centerY
learnScreen:insert(backGround)
home=display.newImageRect( “home.png”,48,48 )
home.x = 800–30
home.y = 75–30
learnScreen:insert(home)
home:addEventListener(“tap”, onHomeClick)
musicon=display.newImageRect( “musicon.png”,48,48 )
musicon.x = 870
musicon.y = 75
learnScreen:insert(musicon)
musicon:addEventListener(“tap”, onMusicOnTap)
musicoff=display.newImageRect( “musicoff.png”,48,48 )
musicoff.x = 870
musicoff.y = 75
learnScreen:insert(musicoff)
musicoff:addEventListener(“tap”, onMusicOffTap)
voiceon=display.newImageRect( “voiceon.png”,48,48 )
voiceon.x = 940
voiceon.y = 75
learnScreen:insert(voiceon)
voiceon:addEventListener(“tap”, onVoiceOnTap)
voiceoff=display.newImageRect( “voiceoff.png”,48,48 )
voiceoff.isVisible=false
voiceoff.x = 940
voiceoff.y = 75
learnScreen:insert(voiceoff)
voiceoff:addEventListener(“tap”, onVoiceOffTap)
referenceIcon=display.newImageRect(“ref.png”,48,48)
referenceIcon.x=730
referenceIcon.y=75
learnScreen:insert(referenceIcon)
referenceIcon:addEventListener(“tap”,onReferenceClick)
slash=display.newImageRect( “slash.png”,22,72 )
slash.x = 715
slash.y = 570
learnScreen:insert(slash)
if isAndroid or isSimulator then
bcMusic=audio.loadSound(“backgroundmusic.mp3”)
else
bcMusic=audio.loadSound(“backgroundmusic.aifc”)
end
----------------------first time ---------------------------
loadFooterAnimals()
rectGroup:addEventListener(“touch”,startDrag)
collectgarbage()
print( "\nMemUsage: " … collectgarbage(“count”) )
local textMem = system.getInfo( “textureMemoryUsed” ) / 1000000
print( "TexMem: " … textMem )
return learnScreen
end [import]uid: 75428 topic_id: 20590 reply_id: 80796[/import]
Can you try changing
[lua]learnScreen:remove(rectGroup)
rectGroup=nil[/lua]
To;
[lua]rectGroup:removeSelf()
rectGroup=nil[/lua]
and let me know if that has an impact? [import]uid: 52491 topic_id: 20590 reply_id: 80808[/import]
Ya…I have tried both but not working. [import]uid: 75428 topic_id: 20590 reply_id: 80813[/import]
Ok, well the next step would be removing this large rectangle entirely from your code (not using it at all) and seeing if you still appear to have a memory leak.
If you don’t then we know for certain it is that one object and could further investigate why it isn’t clearing.
Peach [import]uid: 52491 topic_id: 20590 reply_id: 80978[/import]
By saying removing rectangle if you mean that I should try without inserting 25 images in the screen then that also I’d tried. In fact instead of 25 images if I insert only few images say 6 then the texture memory remains 12 as it was 62 for 25 images.
One more thing I think should be brought to your notice is, at a time only 6 images out of 25 are viewable on screen and rest are inserted at a horizontal distance of 120 of previous image, i.e. the x position of the current image will be previous_image.x+120 and this is applied to all the 25 images. Hence all the images apart form 6 image are out of screen though are inserted in the group. [import]uid: 75428 topic_id: 20590 reply_id: 80988[/import]
This sounds like it may be more related to Director than to Corona itself - could you post in the Director subforum? (The creator of Director answers questions related to the class there.)
Using the current version of Corona (704) I’m not noticing any memory issues myself.
Peach
[import]uid: 52491 topic_id: 20590 reply_id: 81017[/import]
I see a few things diffrent from the way I would code things. For instance
[lua]removeScreenObjs = function()
local k
for k = 1,#screenObjs do
learnScreen:remove(screenObjs[k])
screenObjs[k]=screenObjs[k-1]
screenObjs[k] = nil
end
screenObjs={}
end[/lua]
This I would code like this. It might be the wrong way but hey it works for me for now.
[lua]if platMod then
for i = 1, #platMod do
platMod[i]:removeSelf()
platMod[i] = nil
print “greenPlatformsCleaned”
end
end[/lua]
This is code from my current project.
Notice the print statement. I use tons of print statements in my projects and they help tons.
Also nil out new that will help a little too. imo [import]uid: 39088 topic_id: 20590 reply_id: 81025[/import]
Hi,
I tried your code but it’s not working.
[import]uid: 75428 topic_id: 20590 reply_id: 81028[/import]
Can I see how you used it. Also when you post your code could you please use lua tags its much easier to read.
Thanks [import]uid: 39088 topic_id: 20590 reply_id: 81032[/import]