Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
How to unload resources? — Gideros Forum

How to unload resources?

KirillKirill Member
edited June 2012 in General questions
Problem:

Phone has X megabytes of memory.
Game has few levels Y megabytes each. (for instance, Y = 0.75 * X)
I wonder how I can load first level, then unload it, and load second level immediately.

How I can unload textures manually or in deterministic way.
I can't find answer in documentation.

I tried this code:

texture = nil
collectgarbage("collect")

but it doesn't work.

Sorry for my english, I hope you understand me.

Comments

  • You also need to nil out any sprites, bitmaps or any other resources that are also using that texture first, if any references to the data / resource still exist then they'll never get garbage collected.
    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
  • KirillKirill Member
    Yes, I know. But the texture is only object in the program.
    Maybe GC will release the object later, but I need guaranteed disposal.

    Likes: Kellog

    +1 -1 (+1 / -0 )Share on Facebook
  • There can be a delay with the GC - sometimes resources don't get free'd straight away if there are multiple dependencies, the way to prove it is to load in the texture, list the about of memory used, then set up an EnterFrame listener and continually call the GC and print the results.

    "It's not unusual" :-\" to see the memory total fluctuate around a value and then settle down - it depends on what else Lua is doing at the time.

    (sneaky Tom Jones ref with the smiley :) )
    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
  • atilimatilim Maintainer
    edited June 2012
    Also I prefer to collect twice as:
    collectgarbage("collect")
    collectgarbage("collect")
    Usually a single garbagecollect() doesn't collect all the unreachable objects.
Sign In or Register to comment.