Jump to content

Kill vs Destroy


Meowts
 Share

Recommended Posts

Kill Kill Kill! Deeeestrooooyyyy!!!!!!

 

Okay.

 

So I'm creating something larger than I have before, and I'm concerning myself with memory management and optimizing performance.

 

Okay so:

 

Upon switching screens in the game (not Phaser states, ask if you're interested), every screen/class has their own destroy functions, which go ahead and destroy every sprite, text, button, group or whatever is instantiated for the screen, before loading the next screen.

 

My question is: in terms of avoiding any lingering memory usage for a game that's intended to run for long periods of time (it'll be fun?), is it more consuming to be repeatedly destroying everything, or is it better to just kill (hide) things? If the killed components (say, Sprites) are hanging out in dead land, a) will it affect performance, and/or b ) is it possible to reuse the memory reserved for those dead sprites for new sprites (in the case of sprites)?

Link to comment
Share on other sites

You can profile this in the browser as your game runs to see what the effects are. Truthfully, memory management in JS is kind of an art and the needs tend to be very specialized to the specifics of your app.

 

That said, I tend to prefer "kill"ing things vs. "destroy"ing things so I don't thrash the GC; for example, destroying my player sprite only to make another player sprite immediately afterwards puts pressure on the GC to do its thing.

Link to comment
Share on other sites

Cooooool! I had never looked at the Profile section of dev tools before, thanks! I like the snapshot tool, I can already see where it spikes, this will definitely come in handy!

 

Yeah I can tell it's fairly game specific. Great answer!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...