garbage collection? Do items auto destroy if they go to far off screen?

part12studiospart12studios Member Posts: 620
edited November -1 in Working with GS (Mac)
I am doing a game where a log of objects come down. and pass by.. however once they leave the screen i do nothing with them.. they leave and i assume contine down into infinity?

should i put some kind of timer and destroy behavior after x time passes to insure they are removed from memory?

I'm just wondering if it's worthwhile to only spawn a fixed number of items and just move them around, or is the work involved in doing that about the same as simply spawning a new actor..

platforms like flash who struggle to keep performance good on iPhone encourage making "pools" of items and just working from those. is this a beneficial design in GameSalad?

Thanks!
Caleb

Comments

  • TokuharaTokuhara Member Posts: 94
    You can make a wall and put a rule in your actor
    RULE
    - When collides with ACTOR Wall
    - Destroy this actor

    Or you can make a rule in your actor by position
    RULE
    - ATTRIBUTE self.Position.Y is < 0
    - Destroy this Actor
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Hi Caleb; not sure how far back in the GS Creator betas it was, where we had to put destroy behaviors to stop actors sailing off into infinity (and beyond ;-); I'm also not certain when it was introduced whereby any actor which is 500 pxls or more outside the perimeter of the screen gets automatically destroyed...

    But that's what happens now (or so I learned from this Forum a while back; can't ever remember it being an added feature mentioned in an official update); so no worries about your actors sailing off eating up valuable RAM....

    ---------------------------------------------
    http://www.davidgriffinapps.co.uk/

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • SlickZeroSlickZero Houston, TexasMember, Sous Chef Posts: 2,870
    Yes, they destroy when they go off screen. The memory usually remains reserved when this happens as well. You can have an invisible actor that destroys them, but this is basically the same as letting them drop off out of sight. The memory usage slowly builds up if you have a ton of actors doing this, and eventually crashes.

    And yes, it's better to have a "pool" of actors offscreen that change location when needed, and when they are done, move again offscreen somewhere.
  • part12studiospart12studios Member Posts: 620
    Thanks guys for the responses! That's a great approach Toku, I could see that working very well.. I've had some similar situations I've applied other rules so you confirmed how i thought i might approach it.

    And Gyroscope, thanks for validating. I was pretty sure there must be some kind of auto destroy going on because the performance issues i'm having felt more like speed / accuracy than cpu overload from too many objects on screen at once.
  • part12studiospart12studios Member Posts: 620
    ok cool slickzero I'll have to test that out. it seems like the pool thing would be a good idea in general anyway.. a bit of extra work.. but could free up some fps when things get really intense.

    Thanks!
    Caleb
  • SlickZeroSlickZero Houston, TexasMember, Sous Chef Posts: 2,870
    If you don't have a lot of it going on, using spawn and destroy is fine. It's just when you get a lot of it going on constantly, it builds up the memory usage and doesn't release it. Changing scenes clears up the memory, and I use that to my advantage when I use spawn and destroy a lot. It pretty much releases all available memory when you do that…."Pretty much" being the key word.
  • gariantrollgariantroll Member Posts: 219
    Hey, that is exactly what I was trying to find out because my game seems to be doing this as I switch scenes and that makes a lot of sense the way the games memory moves when I play the game.
  • gariantrollgariantroll Member Posts: 219
    Unfortunately deleting actors before you switch scenes does not prevent my memory from coming back down. What could be the problem? I was thinking maybe having game attributes instead of scene attributes could be the culprit.
Sign In or Register to comment.