Game would crash after few minutes

Hi again I’m encountering this strange problem what happen is I have these two platforms moving horizontally the screen in portrait right. What happens after I think about 3 minutes the platforms would lag a lot and then corona simulator would stop responding what could this be here the code that I did it with.

[code] local physics = require “physics”
physics.start()

local recycle
local transit

local stage = display.newRect(100, 100, 100 ,100)
stage.x = 160
stage.y = 400
physics.addBody(stage ,“static”,{ density = 1.5, friction = 12.0, bounce = 0.0 })

local ball = display.newCircle(10,10,10,10)
ball.x = 160
ball.y = 240
physics.addBody(ball, { density = 1.5, friction = 0.0, bounce = 0.1 })

local paddle = display.newRect(0,500,100,20)
paddle.y = 480
paddle.x0 = 500
physics.addBody(paddle, “static” )

local paddle2 = display.newRect(0,500,100,20)
paddle2.y = 500
paddle2.x0 = 480
physics.addBody(paddle2, “static” )

function transit()
transition.to(paddle, {time=2000 , x = 400 - 600, onComplete= recycle})
transition.to(paddle2, {time=2000, x = 480 - 600, onComplete= recycle})
end

function recycle()
paddle.x = paddle.x0
paddle.y = 50 + math.random( 320 )
paddle2.x = paddle2.x0
paddle2.y = 50 + math.random( 320 )
transit()
end

local onTouch = function(event)
if ball.canJump then
ball:applyLinearImpulse(0, -5, ball.x, ball.y)
end
end
Runtime:addEventListener(“tap”, onTouch)

local function onCollision(self, event )
if ( event.phase == “began” ) then
if event.other.stage then
ball.canJump = true
end
elseif ( event.phase == “ended” ) then
if event.other.stage then
ball.canJump = false
end
end
end
ball.collision = onCollision
ball:addEventListener( “collision”, ball )
transit()[/code]

[import]uid: 17058 topic_id: 19676 reply_id: 319676[/import]

What does memory profiling tell you? [import]uid: 70134 topic_id: 19676 reply_id: 76083[/import]

@thomas6 what do you mean memory profilling? [import]uid: 17058 topic_id: 19676 reply_id: 76092[/import]

@thomas6 what do you mean memory profilling?

sorry for double post [import]uid: 17058 topic_id: 19676 reply_id: 76096[/import]

You are probably getting out of memory.

Suggestion is to put the simple code below, which is provided by Ansca, into your main.lua and check the terminal for the progression of memory usage during your game until it crashes
[lua]–Uncomment to monitor app’s lua memory/texture memory usage in terminal…

local function garbagePrinting()
collectgarbage(“collect”)
local memUsage_str = string.format( “memUsage = %.3f KB”, collectgarbage( “count” ) )
print( memUsage_str )
local texMemUsage_str = system.getInfo( “textureMemoryUsed” )
texMemUsage_str = texMemUsage_str/1000
texMemUsage_str = string.format( “texMemUsage = %.3f MB”, texMemUsage_str )
print( texMemUsage_str )
end[/lua] [import]uid: 67641 topic_id: 19676 reply_id: 76097[/import]

@Raom_games this is what I would get in the terminal

Corona Terminal: line 9: 11418 Terminated “$path/Corona Simulator.app/Contents/MacOS/Corona Simulator” $*
logout

any ideas? [import]uid: 17058 topic_id: 19676 reply_id: 76103[/import]

two questions:

1)is line 9 from your main.lua file the same you posted in your first message (that is ‘stage.y = 400’)? In fact your output says that the crash happens because something went wrong in line 9 of your main.lua
2) are the numbers of memory usage in your terminal constant and or they grow exponentially until crash? If the second, what is the latest value you can read? Golden rule is to keep them (the sum of objects + texture memory usage) well below 5 MB.
[import]uid: 67641 topic_id: 19676 reply_id: 76104[/import]

@Raom_games no that not case I felt like explain my problem a bit wrong ok here I go the problem is that when the two platforms move across the screen for about 30 seconds the simulator slows down then it stops responding. Then what I do is I force quit the simulator. Then I get the error in the terminal.

So I think I said myself wrong I meant to say simulator stops responding so I do fix this problem were the simulator stops responding. [import]uid: 17058 topic_id: 19676 reply_id: 76106[/import]

ok i’m trying your file just now, let’s see what happens

… and i can confirm it is a memory problem

please put the Ansca code into your main file and watch it going up exponentially before crashing … in message #4 it was missing one line so you could not read anything from your terminal… so try this and watch yourself

[lua]local function garbagePrinting()
collectgarbage(“collect”)
local memUsage_str = string.format( “memUsage = %.3f KB”, collectgarbage( “count” ) )
print( memUsage_str )
local texMemUsage_str = system.getInfo( “textureMemoryUsed” )
texMemUsage_str = texMemUsage_str/1000
texMemUsage_str = string.format( “texMemUsage = %.3f MB”, texMemUsage_str )
print( texMemUsage_str )
end
Runtime:addEventListener( “enterFrame”, garbagePrinting )[/lua]

it basically happens that every time your platforms go off the screen and come back, memory usage doubles until crash at 7MB or 14MB or more [import]uid: 67641 topic_id: 19676 reply_id: 76109[/import]

@Raom_games yeah I did see it so whats the solution to this problem

Edit: I just saw mines the simulator froze at when it reached memUsage = 108866.412 KB. [import]uid: 17058 topic_id: 19676 reply_id: 76111[/import]

fatal problem should be here:

[lua]function transit()
transition.to(paddle, {time=2000 , x = 400 - 600, onComplete= recycle})
transition.to(paddle2, {time=2000, x = 480 - 600, onComplete= recycle})
end[/lua]

when calling recycle, you do not get rid of some previous data and memory usage grows exponentially

unfortunately I cannot help with one efficient mode to bypass this behaviour at the moment… so wait for more expert hands

good luck [import]uid: 67641 topic_id: 19676 reply_id: 76112[/import]

@Raom_games well thanks for detecting the problem [import]uid: 17058 topic_id: 19676 reply_id: 76115[/import]