could images size affect memory leak

hey,

I have a game, it’s 848*480, and the check memory function shows that the memory at the start is 291Kb,

but I while I’m playing the memory increases to 2000Kb or more and the game on the device starts to show little lag , but every time I replay the game, it starts with 400Kb and then increases, 

so the question here is that I wondering if it has something to do with the images size ?

Hi @hammod-930,

It’s not unusual for the memory to creep up a little after the first replay. What you need to carefully monitor (and prevent) is any kind of continual up-creep (leak) on each successive replay… in that case, you have a leak. But if your memory jumps up a slight bit on the second replay, then stabilizes (more or less) that should be fine.

Best regards,

Brent

Hi Brebt, 

depending on your post, my game is fine, but if I play in the game for like 3 mins the game starts to show lag anf gets slower,

so I have to lose and play again to play in again in fine but the same scenario happens after I hit the time of 3 or 5 mins. knowing that there are sprite sheets but I remove them within the phase “ended” and set them to nil, and many physics bodies, it could be around a 200 physics bodies or more depending on how long you keep playing the game, can this be a problem ?

200 physics bodies could be a problem, yes, depending on the device. Can you potentially “recycle” these so you’re not dealing with so many in the simulation at one time?

Brent

I’m recycling the objects, and if there’s a collision to the objects, they’ll be removed using ‘object:removeSelf() object = nil’, but I’m also using a transition.to and in ‘onComplete’ I’m using “display.remove(object)” because there’s an error happens if I used ‘removeSelf’ with onComplete, could this be a part of the problem ?

and the other problem is that I have bullets to be shot, but I can’t remove the bullets when collision happens because so objects are “isSensor = true”, I thought about making an objects as walls out of the screen boarders, so when the bullet collides only with the walls it be removed, but I’m not sure if it’s possible ?

My first suggestion is that you always recycle the objects (if they’re part of the 200+) even after you transition them with onComplete. Remember that destroying and creating objects (especially with physics on them) is slightly inefficient, so you’ll benefit by just moving them into some kind of holding queue where they sit idle until they’re needed back in the simulation.

And yes, you can limit which physical objects collide with others (and which don’t) using collision filters.

Best regards,

Brent

I have this function :

[lua]function remove_bullet(e)
if e.phase == “ended” then
print("!")
end
end

bullet:addEventListener(“collision”, remove_bullet)
[/lua]

and I have this variable :

[lua]wall = display.newImage(“wall.png”)
wall.x = 180; wall.y = 860; wall.rotation = 0;
wall.alpha = 0
physics.addBody(wall, “static”)
screenGroup:insert(wall)
transition.to(wall, { alpha = 1, time = 1000})[/lua]

how can I remove the bullet only when it collides with wall ? I read some docs but still don’t know how ?

Hi @hammod-930,

To make some physical objects collide with others (but not necessarily all), you should use collision filters. They are described toward the end of this document:

http://docs.coronalabs.com/guide/physics/collisionDetection/index.html

And then, be sure to link to the “collision filter worksheet” here:

http://forums.coronalabs.com/topic/2128-collision-filters-helper-chart/

I wrote this post a long time ago, but it’s completely valid and it should help you figure out the proper numbers for your collision filters.

Brent

P.S. - remember that if your wall objects are “static” type, anything that collides with them must be “dynamic” type (the default). Objects of “kinematic” type will never collide with “static” or vice-versa. In any physical collision, one of the objects (or both) must be “dynamic”.

@Brent Sorrentino 

with collision filtering I can make object1 collides with object2 avoiding object3, right ?, but I don’t want this, I want the bullet to collide with all objects displayed, but when the bullet collides with the wall I want to remove it, is this possible ?

Yes, of course… you just need to assign some property to objects, like a “.name” or something, and then upon collision, you conditionally compare those properties and take the correct action (or not).

Now that I did assign properties to the wall and it’s (wall.name = “first wall”) and to the bullet (bullet.name = “my bullet”)

can you write for me within this function the code I need, cause it’s easier to understand within sample codes

here’s the function :

  1. function remove_bullet(e)
  2. if e.phase == “ended” then
  3. print("!")
  4. end
  5. end
  6. bullet:addEventListener(“collision”, remove_bullet)

I want to remove the bullet in the collision with wall, can you write me the needed code within the function,

sorry for my english, but it’s not my home language :frowning:

Hello,

It’s best if you refer to the guide on this. There’s an example of assigning “names” to objects and dealing with collisions:

http://docs.coronalabs.com/guide/physics/collisionDetection/index.html

Take care,

Brent

ok, I’ll try,

before 10 mins I was testing my game on my note 3 that has a 3GB of RAM, but the shocking part is that the usage of RAM by the game is 200MB !!! which means low hardware devices will die If this game was played on!!!

do you think it’s because the physics joints ?! I’m using “display.remove(obj)” within transitions instead of “obj:removeSelf()”.

could this be a reason ?!

Hi @hammod-930,

There are any number of things which could be affecting the memory. First, is this core memory or texture memory? Texture memory (from OpenGL textures) can skyrocket pretty fast if you’re not careful how you implement visual objects. Core memory should not be that high, so you’ll need to determine if you’re using plugins, modules that take up a lot of memory, etc. It’s just not clear from an initial report what could be the primary cause.

Brent

Hi @hammod-930,

It’s not unusual for the memory to creep up a little after the first replay. What you need to carefully monitor (and prevent) is any kind of continual up-creep (leak) on each successive replay… in that case, you have a leak. But if your memory jumps up a slight bit on the second replay, then stabilizes (more or less) that should be fine.

Best regards,

Brent

Hi Brebt, 

depending on your post, my game is fine, but if I play in the game for like 3 mins the game starts to show lag anf gets slower,

so I have to lose and play again to play in again in fine but the same scenario happens after I hit the time of 3 or 5 mins. knowing that there are sprite sheets but I remove them within the phase “ended” and set them to nil, and many physics bodies, it could be around a 200 physics bodies or more depending on how long you keep playing the game, can this be a problem ?

200 physics bodies could be a problem, yes, depending on the device. Can you potentially “recycle” these so you’re not dealing with so many in the simulation at one time?

Brent

I’m recycling the objects, and if there’s a collision to the objects, they’ll be removed using ‘object:removeSelf() object = nil’, but I’m also using a transition.to and in ‘onComplete’ I’m using “display.remove(object)” because there’s an error happens if I used ‘removeSelf’ with onComplete, could this be a part of the problem ?

and the other problem is that I have bullets to be shot, but I can’t remove the bullets when collision happens because so objects are “isSensor = true”, I thought about making an objects as walls out of the screen boarders, so when the bullet collides only with the walls it be removed, but I’m not sure if it’s possible ?

My first suggestion is that you always recycle the objects (if they’re part of the 200+) even after you transition them with onComplete. Remember that destroying and creating objects (especially with physics on them) is slightly inefficient, so you’ll benefit by just moving them into some kind of holding queue where they sit idle until they’re needed back in the simulation.

And yes, you can limit which physical objects collide with others (and which don’t) using collision filters.

Best regards,

Brent

I have this function :

[lua]function remove_bullet(e)
if e.phase == “ended” then
print("!")
end
end

bullet:addEventListener(“collision”, remove_bullet)
[/lua]

and I have this variable :

[lua]wall = display.newImage(“wall.png”)
wall.x = 180; wall.y = 860; wall.rotation = 0;
wall.alpha = 0
physics.addBody(wall, “static”)
screenGroup:insert(wall)
transition.to(wall, { alpha = 1, time = 1000})[/lua]

how can I remove the bullet only when it collides with wall ? I read some docs but still don’t know how ?