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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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