Hi... Sorry for asking silly questions again and again..
I went through the links you provides above, but I didn't understand how to free the memory each time.. I found following code
localfunction gc()collectgarbage()collectgarbage()collectgarbage()collectgarbage()end
gc()local mem1 =collectgarbage("count")local t ={}-- create an empty tablefor i=1,10000do-- put another 10000 empty tables in it
t[i]={}end
gc()local mem2 =collectgarbage("count")for i=1,10000do-- empty the table (now this table has no fields)
t[i]=nilend
gc()local mem3 =collectgarbage("count")
t =nil-- set table as nil
gc()local mem4 =collectgarbage("count")print(mem1, mem2, mem3, mem4)
I just understood that collectgarbage() is use to collect the memory leak... But Did't understand how and where to use these codes in the project...
@Sush19 Some tips; -In scenemanager when changing scenes remove not used listeners. -Try not to use global variables, as far as i know global variables eats more memory, change them to local which you can of course. -Do not load all your assets in the very beginning if you will not use them. Whenever your job is finished with an asset if it will not be repeatedly used, null it so that collectgarbage can free space.
Your problem "increase in replays" can be caused by in every replay new object will be created without disposing the old one.
Hello @talis, Thank you for your tips... I've only 3 Scenes 1st Scene has only one background image with a play button image and a event listener for the button, and also with background sound...
2nd Scene is the game Scene where I'm loading entire images, fonts, sounds and all with event listeners...
3rd Scene is similar to 1st Scene, with different background, sounds, total score, bonus and replay button...
On game over I'me changing the Scene, i.e from 2nd Scene to 3rd Scene And on replay I'm just changing the Scene, i.e from 3rd Scene to 2nd Scene...
How do I dispose the old sprites and all...? Is there any method to remove all the sprites and make it nil from the Scene, or we have to manually do it for each sprites...
Comments
Sorry for asking silly questions again and again..
I went through the links you provides above, but I didn't understand how to free the memory each time.. I found following code
But Did't understand how and where to use these codes in the project...
I simply added
Each time i replay the games the count increases...
No idea what to do...
Some tips;
-In scenemanager when changing scenes remove not used listeners.
-Try not to use global variables, as far as i know global variables eats more memory, change them to local which you can of course.
-Do not load all your assets in the very beginning if you will not use them. Whenever your job is finished with an asset if it will not be repeatedly used, null it so that collectgarbage can free space.
Your problem "increase in replays" can be caused by in every replay new object will be created without disposing the old one.
Thank you for your tips...
I've only 3 Scenes
1st Scene has only one background image with a play button image and a event listener for the button, and also with background sound...
2nd Scene is the game Scene where I'm loading entire images, fonts, sounds and all with event listeners...
3rd Scene is similar to 1st Scene, with different background, sounds, total score, bonus and replay button...
On game over I'me changing the Scene, i.e from 2nd Scene to 3rd Scene
And on replay I'm just changing the Scene, i.e from 3rd Scene to 2nd Scene...
How do I dispose the old sprites and all...?
Is there any method to remove all the sprites and make it nil from the Scene, or we have to manually do it for each sprites...
But in some cases, you may leave global objects (forgetting to add local before, etc, which can leak memory.)
You can try out this classes by @bowerandy to print out all the current objects:
http://giderosmobile.com/forum/discussion/comment/20247#Comment_20247
And here are the instructions on how to set this up:
http://giderosmobile.com/forum/discussion/comment/20257#Comment_20257
Put something like that in your game scene (change class and method names to what you use):