Trouble with memory optimization

It is a variable that counts the quantity of asteroids. I made that you said, and it shows “74” (that is the correct quantity of asteroids)
The code is:

aux = 0
for i = 1, cuentaasteroides do

aux = aux + 1
if asteroide[aux] ~= nil then
transition.cancel( asteroide[aux].transicion)
display.remove(asteroide[aux])
asteroide[aux] = nil
end
end
print(cuentaasteroides)

Is it correct?

Hi @facuala,

Well, it’s easier if you just check the count of asteroids in the table, instead of using so many variables (these aren’t really necessary here). So, loop from 1 to the number of objects inside the “asteroide” table as I showed in my code a few responses back. Then, tell me what the number of the “print()” statement is.

Brent

Ok, thanks! Now I understood :slight_smile:
I’ll do that tomorrow, because it’s too late and I have things to do.
In 8 or 9 hours I’ll post the result.

Anyway (maybe it doesn’t mind), I never know the exact number of asteroids, it depends of a random that decides if in a line appear 1 or 2 asteroids at the same time.
A lot of thanks!

The result of print(#asteroide) is 0. :confused:   

Hi @facuala,

Unfortunately, it seems like you have a memory leak somewhere else. I would like to help you further, but finding memory leaks can only successfully be done on your side, by carefully examining every aspect of your code, and following along, tracking variables and the number of items in tables, etc. We all struggle with it sometimes, and it requires persistence to locate the source of the issue.

Best of luck,

Brent

I couldn’t work in that today. But testing the game I discovered that after 20,or 30 restarts the colours become worst (some lines disappear, and the game is more dark).

Another thing that misleads me is that before I found the error of the transitions, game becomes slow when Memory Usage reaches 2500 kb.

But now, memory usage increases only 1 kb (average) per restart, and become slower at 520kb (after 20 restarts, like before).

And also appeared the problem that detract colors, I think that the two are related.

Thanks for your support!

Resolved: apparently I’m not very smart .

It was true that there were problems with memory, and thanks to this conflict, I solved them.
The low framerate was generated by a practically invisible background that I put with a listener to avoid conflicts with multitouch.

I forgot to remove it and that’s why the colors became opaque.

Thanks for your support!