Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Garbage Collection and Best Practices for Memory Management? — Gideros Forum

Garbage Collection and Best Practices for Memory Management?

______ Member
edited July 2012 in General questions
I'm creating several objects in one scene, then switching to another. Is there any way to test how much memory I'm using?

I don't want my game to slow down after playing 20-30 levels.

Is there any way to release objects manually? Any other suggestions/tips?

Disclaimer: I don't know much about Garbage Collection.
People call me "underscore".
Tagged:

Comments

  • I'm somewhat new to this, so I can't answer too well, but I do know you can call collectgarbage() manually. I had at least once instance in my tests where I had to do this because I was relying on the collector with a weak table by key setup.
  • petecpetec Member
    You can use
    print(math.floor(collectgarbage("count")))
    to see how much memory is being used. I use it when changing scenes to check for memory leaks.
    I also collect garbage a few times before this as I've found it helps me see if it's my code that's causing memory build up or just a delay in automatic garbage collection, so I actually use:
    collectgarbage()
    collectgarbage()
    collectgarbage()
    print(math.floor(collectgarbage("count")))
  • ______ Member
    @petec That looks nice!

    Do you do anything special when changing scenes, to make sure that the objects are released? How much memory leak do you normally see when changing scenes with/without manual garbage collection?
    People call me "underscore".
  • petecpetec Member
    I just make sure that I manually remove any objects that are not added to the scene sprite (e.g. if I have used stage:addChild(object) ). I also make sure that I remove any eventListeners - although I think (but don't know!) that event listeners attached to objects should be removed when the object is removed.

    Memory use seems to depend on what sort of things are in the scene, but what I watch out for is that it dooesn't keep building up. I sometimes see a small increase for a while but it flattens out and stops increasing and then, as garbage collection does it work, tends to drop back again. When I have a leak, then I see the memory use steadily increase continuously.
  • ______ Member
    @petec

    Just ran your code on my game. Usage seems pretty stable.
    Memory Usage: 	214
    Memory Usage: 	217
    Memory Usage: 	222
    Memory Usage: 	252
    Memory Usage: 	266
    Memory Usage: 	234
    Memory Usage: 	256
    Memory Usage: 	287
    Memory Usage: 	310
    Memory Usage: 	339
    Memory Usage: 	351
    Memory Usage: 	380
    Memory Usage: 	403
    Memory Usage: 	437
    Memory Usage: 	459
    Memory Usage: 	308
    Memory Usage: 	324
    Memory Usage: 	353
    Memory Usage: 	357
    Memory Usage: 	360
    Memory Usage: 	376
    Memory Usage: 	379
    Memory Usage: 	383
    Memory Usage: 	412
    Memory Usage: 	434
    Memory Usage: 	462
    Memory Usage: 	478
    Memory Usage: 	410
    Memory Usage: 	340
    Memory Usage: 	369
    Memory Usage: 	384
    Memory Usage: 	413
    Memory Usage: 	429
    Memory Usage: 	453
    Memory Usage: 	477
    Memory Usage: 	511
    Memory Usage: 	530
    Memory Usage: 	558
    Memory Usage: 	474
    Memory Usage: 	347
    Memory Usage: 	359
    Memory Usage: 	388
    Memory Usage: 	410
    Memory Usage: 	439
    Question: What unit is this number in?
    People call me "underscore".
  • ______ Member
    Maybe @atilim can help :-B
    People call me "underscore".
  • according to:

    http://pgl.yoyo.org/luai/i/collectgarbage

    "count": returns the total memory in use by Lua (in Kbytes).

    :)
    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
  • ______ Member
    Hmm. Any way to measure the total memory usage? The memory that will be used by a real device. With textures and all...
    People call me "underscore".
Sign In or Register to comment.